新手上路
- 积分
- 33
- 金钱
- 33
- 注册时间
- 2017-12-1
- 在线时间
- 13 小时
|
10金钱
#define MAX_SENSOR_BUF_LEN 64
#define SENSOR_RXBUF_LEN 7
#define SENSOR_TXBUF_LEN 8
static uint8_t sensorUartBuffer[MAX_SENSOR_BUF_LEN];
static uint8_t sensorUartBufferIndex = 0;
static uint8_t sensorReportEnabled = 0;
static uint8_t prxbuff = 0;
//static uint8_t ptxbuff = 0;
static uint8_t rxbuff[SENSOR_RXBUF_LEN];
static uint8_t txbuff[SENSOR_TXBUF_LEN] = {0x30,0x03,0x00,0x06,0x00,0x01,0x60,0x2A}; //PM2.5
uint16_t i=0;
uint8_t *pSend;
pSend = txbuff;
HAL_Delay(5000);
while(i++ < SENSOR_TXBUF_LEN)
{
if(HAL_UART_Transmit(&MyDebugUart,(uint8_t *)(pSend++),1,5000) != HAL_OK)
{
debug_print("HAL_UART_Transmit fail!");
}
}
if( HAL_UART_Receive_IT(&MyDebugUart,(uint8_t *)sensorUartBuffer,1) != HAL_OK )
{
debug_print("HAL_UART_Receive fail!");
}
for(size_t i=0;i<=sizeof(rxbuff)-1;i++)
{
debug_print("@%d %x@",rxbuff[i],rxbuff[i]);
}
中断处理函数:
void sensorIRQHandler(void)
{
uint8_t data;
if((MyDebugUart.Instance->SR) & UART_FLAG_RXNE)
{
CLEAR_BIT(MyDebugUart.Instance->SR,UART_FLAG_RXNE|UART_FLAG_ORE);
data = MyDebugUart.Instance->DR;
/*
sensorUartBuffer[sensorUartBufferIndex++] = data;
if(sensorUartBufferIndex >= MAX_SENSOR_BUF_LEN)
{
sensorUartBufferIndex = 0;
}
*///
rxbuff[prxbuff++] = data;
HAL_UART_Receive_IT(&MyDebugUart,(uint8_t *)sensorUartBuffer,1);
if(prxbuff >= MAX_SENSOR_BUF_LEN)
{
prxbuff = 0;
}
}
}
打印的:0`*HAL_UART_Receive fail!@0 0@@0 0@@0 0@@0 0@@0 0@@0 0@@0 0@
**********************
|
|