I did a test, mobile phone sends data to DA14580 device , is displayed in the serial debugging assistant, this is no problem.
But the computer sends data to DA14580 device by uart , the DA14580 device after receiving and printing in serial debugging assistant, data will be wrong
void uart_init_func(uint8_t baudr, uint8_t mode ) //uart init
{
SetBits16(CLK_PER_REG, UART1_ENABLE, 1); // enable clock for UART 1
SetWord16(UART_LCR_REG, 0x80); // set bit to access DLH and DLL register equal SetBits16(UART_LCR_REG,UART_DLAB,1);
#if 0
SetWord16(UART_IER_DLH_REG,(UART_BAUDRATE_115K2&0xFF>>8));//set high byte
SetWord16(UART_RBR_THR_DLL_REG,UART_BAUDRATE_115K2&0xFF);//set low byte
#else
SetWord16(UART_IER_DLH_REG,(UART_BAUDRATE_9K6&0xFF>>8));//set high byte
SetWord16(UART_RBR_THR_DLL_REG,UART_BAUDRATE_9K6&0xFF);//set low byte
#endif
SetWord16(UART_LCR_REG,3);
SetBits16(UART_MCR_REG, UART_SIRE, 0); // mode 0 for normal , 1 for IRDA
SetWord16 (UART_IIR_FCR_REG, 1);/ /启用fifo
SetBits16(UART_IER_DLH_REG,ERBFI_dlh0,1); // IER access, enable interrupt for available data
NVIC_EnableIRQ(UART_IRQn);
NVIC->ICPR[UART_IRQn]=1;
}
void UART_Handler_func(void) //uart receiving handler
{
uint32_t idd;
idd = 0x0F & GetWord32(UART_IIR_FCR_REG);
if(idd!=NO_INT_PEND)
{
switch(idd)
{
case UART_TIMEOUT:
if ((uart_env.errordetect == UART_ERROR_DETECT_ENABLED) && uart_fifo_err_getf())
{
uart_rec_error_isr();
}
break;
case RECEIVED_AVAILABLE:
uart_rec_data_avail_isr(); // Reception data processing
break;
case THR_EMPTY:
uart_thr_empty_isr();
break;
default:
break;
}
}
}
static void uart_rec_data_avail_isr(void) //
{
while (uart_data_rdy_getf())
{
// Read the received in the FIFO
uart_rev_buf[rev_buf_index] = uart_rxdata_getf(); //
// Update rev_buf_index
rev_buf_index++;
// Check if uart_rev_buf is full
if (rev_buf_index == 2)
{
rev_buf_index = 0;
uart_write(uart_rev_buf,2,NULL); //Print Functions
uart_rev_buf[0]=0;
uart_rev_buf[1]=0;
}
}
}
