linux串口只能接收16个字节,UART1串口只能接收16个字节的数据,超过16个字节的数据全部丢失...

UART1串口只能接收16个字节的数据,超过16个字节的数据全部丢失

[复制链接]

void uart1IsrInit(void)

{

INT16U usFdiv;

U1LCR  = 0x87;                                                      // 允许设置波特率,8位数据,2位停止位

usFdiv = (FPCLK / 16) / UART_BPS;                                   // 设置波特率

U1DLM  = usFdiv / 256;

U1DLL  = usFdiv % 256;

U1LCR  = 0x07;                                                      // 锁定波特率

//    U1FCR  = 0x87;                                                      // 使能FIFO,设置8个字节触发点

U1FCR  = 0x07;                                                      // 使能FIFO,设置1个字节触发点

U1IER  = 0x01;                                                      // 使能接收中断

}上面是我的初始化程序,波特率为38400。先是使用8个字节的触发点,发现接收到16个字节后,U1LSR.0位被清除;然后改为一个字节触发一次,依然是到16个字节后,U1LSR.0位被清除。请各位帮我找找问题所在,谢谢了!以下为我的中断程序。

void uart1Isr (void)

{

while ((U1IIR & 0x01) == 0)           //  判断是否有中断挂起

{

switch (U1IIR & 0x0e)           //  判断中断标志

{

case 0x04:                                                  //  接收数据中断

uc_RcvBuf[uc_RcvNum++] = U1RBR;

if((U1LSR & 0x01) == 0)

{

uc_RcvNewFlag = 1;

uc_RcvNum = 0;

}

break;

case 0x0C:                                                  //  字符超时中断

while((U1LSR & 0x01) == 0x01)       //  判断数据是否接收完毕

{

uc_RcvBuf[uc_RcvNum++] = U1RBR;

}

uc_RcvNum = 0;

uc_RcvNewFlag = 1;

break;

default:

break;

}

}

}

数据是不定长的。谢谢各位了!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个基于AT32F421的串口接收发送8个字节数据的代码示例: ```c #include <stdio.h> #include "at32f4xx.h" #define UART_TX_PIN GPIO_Pin_9 #define UART_RX_PIN GPIO_Pin_10 #define UART_GPIO_PORT GPIOA #define UART_GPIO_CLK RCC_APB2Periph_GPIOA #define UART_CLK RCC_APB1Periph_USART2 #define UART USART2 void init_uart() { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; // Enable GPIO clock RCC_APB2PeriphClockCmd(UART_GPIO_CLK, ENABLE); // Enable UART clock RCC_APB1PeriphClockCmd(UART_CLK, ENABLE); // Configure UART pins GPIO_InitStructure.GPIO_Pin = UART_TX_PIN | UART_RX_PIN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(UART_GPIO_PORT, &GPIO_InitStructure); // Configure UART USART_InitStructure.USART_BaudRate = 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(UART, &USART_InitStructure); // Enable UART USART_Cmd(UART, ENABLE); } void uart_send(uint8_t *buf, uint8_t len) { uint8_t i; for (i = 0; i < len; i++) { USART_SendData(UART, buf[i]); while (USART_GetFlagStatus(UART, USART_FLAG_TXE) == RESET); } } void uart_receive(uint8_t *buf, uint8_t len) { uint8_t i; for (i = 0; i < len; i++) { while (USART_GetFlagStatus(UART, USART_FLAG_RXNE) == RESET); buf[i] = USART_ReceiveData(UART); } } int main(void) { uint8_t tx_buf[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; uint8_t rx_buf[8]; // Initialize UART init_uart(); // Send data uart_send(tx_buf, 8); // Receive data uart_receive(rx_buf, 8); // Do something with received data while (1); } ``` 在这个示例中,我们使用USART2作为串口,并使用PA9和PA10作为UART的TX和RX引脚。我们首先需要初始化UART,然后可以使用uart_send()函数发送8个字节数据,并使用uart_receive()函数接收8个字节数据。在上面的示例中,我们只是打印收到数据

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值