|
本帖最后由 SGHTUEPOM 于 2021-3-19 18:13 編輯
論壇的各位大師可以幫忙下這個(gè)RS485的程序的問題點(diǎn),
可以發(fā)送接收不到。。
主板的485接口是兩線的,連接到了CP2104的T+/T-,CP2104的另一端接口通過USB連接到了電腦。。。
單片機(jī)源程序如下:
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "led.h"
- #include "lcd.h"
- #include "key.h"
- #include "rs485.h"
- #include "usart4.h"
- int main(void)
- {
- u8 key;
- u8 i=0,t=0;
- u8 cnt=0;
- u8 rs485buf[5];
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設(shè)置系統(tǒng)中斷優(yōu)先級(jí)分組2
- delay_init(168); //初始化延時(shí)函數(shù)
- uart_init(115200); //初始化串口波特率為115200
- RS485_Init(115200); //初始化RS485串口3
- My_USART4_Init(115200);
- while(1)
- {
- for(i=0;i<5;i++)
- {
- rs485buf[i]=cnt+i;//填充發(fā)送緩沖區(qū)
- }
- RS485_Send_Data(rs485buf,5);//發(fā)送5個(gè)字節(jié)
- delay_ms(500);
- RS485_Receive_Data(rs485buf,&key);
-
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
STM32-RS485.7z
(311.65 KB, 下載次數(shù): 23)
2021-3-19 17:56 上傳
點(diǎn)擊文件名下載附件
|
|