|
|
View previous topic :: View next topic |
Author |
Message |
harizal
Joined: 13 Apr 2018 Posts: 3 Location: Malaysia
|
How To send data on INT32 through I2C |
Posted: Wed May 02, 2018 2:12 am |
|
|
Master Code:
int32 binary;
binary=112000010; // 9digit like a integer number
Printf("TX: %Lu \n",binary);
delay_ms(1);
i2c_start(); // Start condition
i2c_write(0xa0); // Device address
i2c_write(binary); // Write Command 0000000000000
i2c_stop(); // Stop condition
Slave Code:
int32 incoming;
incoming = i2c_read();
printf("\n\rRead byte 1: %Lu \n\r", incoming);
incoming = i2c_read();
printf("Read byte 2: %Lu \n\r\n\r", incoming);
But the data receive on hexa value. How to send INT32 data through I2C from master to slave. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19537
|
|
Posted: Wed May 02, 2018 2:39 am |
|
|
You have to send it byte at a time.
All I2C transfers are 8bit.
Code: |
i2c_start(); // Start condition
i2c_write(0xa0); // Device address
i2c_write(make8(binary,3)); // Top byte
i2c_write(make8(binary,2)); // Next
i2c_write(make8(binary,1)); // penultimate
i2c_write(make8(binary,0)); // final
i2c_stop(); // Stop condition
|
Code: |
int32 incoming;
byte B3,B2,B1,B0;
while (i2c_isr_state!=0)
; //wait for address byte to arrive
//Now we have the address - read it
B0=i2c_read();
//Now the next four bytes will be the data
B3 = i2c_read();
B2 = i2c_read();
B1 = i2c_read();
B0 = i2c_read();
incoming=make32(B3,B2,B1,B0);
printf("\n\rRead byte 1: %Lu \n\r", incoming);
//incoming = i2c_read();
//printf("Read byte 2: %Lu \n\r\n\r", incoming);
//You can't do another read here you need to go back
//to wait for the address again.
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|