OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 5835|回复: 2

請教STM32F429 USART 接收值問題

[复制链接]

1

主题

1

帖子

0

精华

新手入门

积分
25
金钱
25
注册时间
2015-11-19
在线时间
0 小时
发表于 2015-11-19 13:55:48 | 显示全部楼层 |阅读模式
5金钱
各位前輩好,我目前是使用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,因此我想請教為什麼需要發送兩次回傳值才會正確?
感謝各位前輩的幫忙!!
[mw_shl_code=c,true]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; } } [/mw_shl_code]


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165371
金钱
165371
注册时间
2010-12-1
在线时间
2110 小时
发表于 2015-11-19 22:55:58 | 显示全部楼层
回复

使用道具 举报

1

主题

16

帖子

0

精华

初级会员

Rank: 2

积分
64
金钱
64
注册时间
2015-9-6
在线时间
7 小时
发表于 2015-11-29 22:52:00 | 显示全部楼层
请问你有F429开发板是在那买的呢???资料齐全不??我也想买一块,能发个网址吗?
回复

使用道具 举报

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

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-2-25 18:39

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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