Abdelmalek BELLOULA
/
mbed_blinko
TEST 485
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include <RS485.h> 00003 Serial pc(USBTX, USBRX); 00004 RS485 RS485(p13,p14,p15); // Tx, Rx , !RE and DE MAX485 pin 00005 00006 DigitalOut ho(p15); // this pin should be connected to !RE and DE 00007 typedef uint8_t byte; 00008 00009 byte regvalue[9]; 00010 //byte data[9] = {0x01,0x04,0x00,0x48,0x00,0x02,0xf1,0xdd};//your data 00011 byte data[9] = {0x02,0x05,0x01,0x49,0x01,0x03,0xf2,0xde};//your data 00012 int main() 00013 { 00014 pc.baud(115200); 00015 pc.printf("main\n"); 00016 while(1) { 00017 pc.printf("Starting\n"); 00018 ho = 1; // Enable sending on MAX485 00019 RS485.sendMsg(data,sizeof(data)); 00020 wait_ms(600); // Must wait for all the data to be sent 00021 ho = 0; // Enable receiving on MAX485 00022 pc.printf("Getting data\n"); 00023 if(RS485.readable() >0){ 00024 memset(regvalue,0,sizeof(regvalue)); 00025 wait_ms(200); 00026 RS485.recvMsg(regvalue,sizeof(data),500); 00027 wait_ms(200); 00028 for (int count = 0; count < 9; count++) { 00029 pc.printf("%X - ", regvalue[count]); 00030 } 00031 }else printf("No Data\n"); 00032 printf("Done\n"); 00033 wait_ms(1000); 00034 } 00035 }
Generated on Sat Jul 23 2022 14:41:56 by 1.7.2