硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3239|回复: 1
收起左侧

請教STM32F429 USART 接收值問題

[复制链接]

3

主题

3

回帖

3

积分

新手上路

积分
3
发表于 2015-11-19 10:21:45 | 显示全部楼层 |阅读模式
各位前輩好,我目前是使用STM32F429的開發版,進行UASART的傳送與接收值,而在開發的過程中遇到了使用USART接收值的問題,如下詳述:
下是我目前使用的USART接收值的程式:
程式主要執行當ble_rx_buff收到SEND_START XXXX就將XXXX的值使用printf回傳顯示收到的數值,
而我目前發生的情形是我從電腦發送SEND_START 0000 則STM32F429 開發板會回傳0000,然後在下一次從電腦發送SEND_START 0001 則STM32F429 開發板會回傳0000,
要再從電腦發送一次SEND_START 0001 之後STM32F429 開發板才會回傳0001,因此我想請教為什麼需要發送兩次回傳值才會正確?
感謝各位前輩的幫忙!!

void USART1_IRQHandler(void){
    int i = 0;
    if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET){
        ble_rx_buff[ble_rx_index] = USART_ReceiveData(USART1);
        if(ble_rx_index >= 14 &&
                ble_rx_buff[ble_rx_index - 14] == 'S' &&
                ble_rx_buff[ble_rx_index - 13] == 'E' &&
                ble_rx_buff[ble_rx_index - 12] == 'N' &&
                ble_rx_buff[ble_rx_index - 11] == 'D' &&
                ble_rx_buff[ble_rx_index - 10] == '_' &&
                ble_rx_buff[ble_rx_index - 9] == 'S' &&
                ble_rx_buff[ble_rx_index - 8] == 'T' &&
                ble_rx_buff[ble_rx_index - 7] == 'A' &&
                ble_rx_buff[ble_rx_index - 6] == 'R' &&
                ble_rx_buff[ble_rx_index - 5] == 'T' &&
                ble_rx_buff[ble_rx_index - 4] == ' ' ) {
            Thousands = hex_to_dec(ble_rx_buff[ble_rx_index - 3])<<12;
            Hundreds = hex_to_dec(ble_rx_buff[ble_rx_index - 2])<<8;
            Tens = hex_to_dec(ble_rx_buff[ble_rx_index - 1])<<4;
            Ones = hex_to_dec(ble_rx_buff[ble_rx_index - 0]);
            Total = Thousands + Hundreds + Tens + Ones;
            printf("%04X",(unsigned short)(Total));
            new_command = 3;
            ble_rx_index = 0;
        }
        ble_rx_index++;
        ble_rx_index = ble_rx_index & 0x7F;
    }

}
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117530
QQ
发表于 2015-11-19 14:28:06 | 显示全部楼层
这个printf的重定向是怎么实现的,是阻塞的方式实现的吗,还是中断的方式。

另外楼主先测试个简单的,电脑端发一个简单的字母,然后返回看看有问题不,一点点排查下,只看楼主的代码没啥问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-8-13 01:16 , Processed in 0.038050 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表