CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How To send data on INT32 through I2C

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
harizal



Joined: 13 Apr 2018
Posts: 3
Location: Malaysia

View user's profile Send private message

How To send data on INT32 through I2C
PostPosted: Wed May 02, 2018 2:12 am     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Wed May 02, 2018 2:39 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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