现在我stm32外接了一个12位的AD模块,它将数据分高八位和第八位分别通过串口接收,然后传给上位机,最终我想在串口助手上显示AD采集的数据,可是不能显示。只有在主函数的while()语句中加入USART_SendData(USART1, DATE_1115[0]);和USART_SendData(USART1, DATE_1115[1]);这两句话才能显示。我想不写这两句话就要显示,怎样改程序,求大神们帮着看看,小弟十分感谢!
u8 USART_RX_BUF[64]; //接收缓冲,最大64个字节.
void uart_init(u32 bound)
{
//GPIO端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);
//USART1_TX PA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1_RX PA.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART 初始化设置
USART_InitStructure.USART_BaudRate = bound;//一般设置为9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启中断
USART1->DR=DATE_1115[0]; //将外部16位AD的高8位数据写给串口的数据寄存器
while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE)==SET)//判断接收寄存器是否为空
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE);
}
USART1->DR=DATE_1115[1]; //将外部16位AD的低8位数据写给串口的数据寄存器
USART_Cmd(USART1, ENABLE); //开启串口1
}
int main(void)
{
u16 data;
SystemInit();
RCC_Configuration();
delay_init(72);
NVIC_Configuration();
uart_init(9600);//串口初始化为9600
I2C_Configuration();
while(1)
{
Confige1115(3); //初始化ADS1115
read1115(); //读取ADS1115采集的数据
data = USART_ReceiveData(USART1); //获取串口最近一次接收到的数据
delay_ms(100);
if(data != 0)
{
USART_SendData(USART1,data); //将接收寄存器中的数据发送出去
}
}
}
|