工程:以TI提供协议栈BLE-CC254X-1.4.2.2中SimpleBLEPeripheral为例程,HAL_LCD=FALSE/HAL_KEY=FALSE/HAL_UART=TRUE。
因为板子中采用UART0-ALT2改如下代码:
1.HalUARTInitDMA()函数中PERCFG &= ~HAL_UART_PERCFG_BIT;改为PERCFG |= HAL_UART_PERCFG_BIT;
#define PxSEL P1SEL
#define HAL_UART_PERCFG_BIT 0x01 // USART0 on P0, Alt-1; so clear this bit.
#define HAL_UART_PRIPO 0x00 // USART0 priority over UART1.
#define HAL_UART_Px_CTS 0x04 // Peripheral I/O Select for CTS flow control.
#define HAL_UART_Px_RTS 0x08 // Peripheral I/O Select for RTS must be manual.
#define HAL_UART_Px_SEL 0x30 // Peripheral I/O Select for Rx/Tx.
2.在main()函数中 HalDriverInit();下面一行增加uart0_open();
static void npi_uart0_callback(uint8 port,uint8 events)
{
if(events&(HAL_UART_RX_FULL|HAL_UART_RX_TIMEOUT))
{
uint8 len = 0;
uint8 buff[200];
len = NPI_RxBufLen();
if(0!= len)
{
NPI_ReadTransport(buff,len);
buff[100] = 0xA0;buff[101] = 0xA1;buff[102] = 0xA2;buff[103] = 0xA3;buff[104] = 0xA4;
buff[105] = buff[0];buff[106] = buff[1];buff[107] = 0xA7;buff[108] = 0xA8;buff[109] = 0xA9;
NPI_WriteTransport(&buff[100],10);
}
}
}
void uart0_open(void)
{
NPI_InitTransport(npi_uart0_callback);
}
问题:
每隔100ms(用100-500ms都测试过)连续发送0X41 0X42,设备有时发送 A0 A1 A2 00 00 00 A4 41 42 A7 A8 A9?
da qin zheng sheng:
不要带串口硬件控制引脚试试。