Abdelmalek BELLOULA
/
mbed_blinko
TEST 485
Revision 0:84c281baac9c, committed 2020-03-05
- Comitter:
- belloula
- Date:
- Thu Mar 05 10:28:10 2020 +0000
- Commit message:
- TEST UART 485
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RS485.lib Thu Mar 05 10:28:10 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/Allar/code/RS485/#6a8a69b660c2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 05 10:28:10 2020 +0000 @@ -0,0 +1,35 @@ + #include "mbed.h" + #include <RS485.h> + Serial pc(USBTX, USBRX); + RS485 RS485(p13,p14,p15); // Tx, Rx , !RE and DE MAX485 pin + + DigitalOut ho(p15); // this pin should be connected to !RE and DE + typedef uint8_t byte; + + byte regvalue[9]; + //byte data[9] = {0x01,0x04,0x00,0x48,0x00,0x02,0xf1,0xdd};//your data + byte data[9] = {0x02,0x05,0x01,0x49,0x01,0x03,0xf2,0xde};//your data + int main() + { + pc.baud(115200); + pc.printf("main\n"); + while(1) { + pc.printf("Starting\n"); + ho = 1; // Enable sending on MAX485 + RS485.sendMsg(data,sizeof(data)); + wait_ms(600); // Must wait for all the data to be sent + ho = 0; // Enable receiving on MAX485 + pc.printf("Getting data\n"); + if(RS485.readable() >0){ + memset(regvalue,0,sizeof(regvalue)); + wait_ms(200); + RS485.recvMsg(regvalue,sizeof(data),500); + wait_ms(200); + for (int count = 0; count < 9; count++) { + pc.printf("%X - ", regvalue[count]); + } + }else printf("No Data\n"); + printf("Done\n"); + wait_ms(1000); + } + } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Mar 05 10:28:10 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file