Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 5, 3 & 1 Forum Discussions

adpac_1560036
Level 4
Level 4
First like received First like given

Hi,

   

Could you please tell me how to send 16 bits of data through I2C?

   

I wonder how i should allocate address at the slave for the data transmitted from master.

   

Thank you.

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

This question can be reduced to "How to access an integer bytewise". There are several different choices.

   

some (not all) are:

   

You could use a union

   

You could directly calculate by shifting and masking

   

you could use a type-cast

   

Because different MCUs may have different endianess, only the shift and mask method is independent.of that.

   

 

   

Bob

View solution in original post

0 Likes
6 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

This question can be reduced to "How to access an integer bytewise". There are several different choices.

   

some (not all) are:

   

You could use a union

   

You could directly calculate by shifting and masking

   

you could use a type-cast

   

Because different MCUs may have different endianess, only the shift and mask method is independent.of that.

   

 

   

Bob

0 Likes

Yeah Bob.

   

Should I require to initialise the read buffer at slave separately to read two bytes?

   

And also please help me how to send the two bytes from master

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

So, what is your I2C master and what is the slave? Provide a datasheet link when not a PSoC. Consider posting your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

sending bytes will work as

   

int Myinteger = 0xBeaf;

   

 

   

    I2C_MasterWriteByte((void *)(&MyInteger));   // Send upper byte

   

    I2C_MasterWriteByte((void *)(&MyInteger)+1);   // Send lower byte

   

 

   

Bob

adpac_1560036
Level 4
Level 4
First like received First like given

PSoC 3 is Master.

   

Im trying to program SI4703 fm receiver through I2C.So, Im unable to know what is happening at the slave. Im not completely done with coding Bob. Il upload a other I2C Master Slave project. Could you please do the changes in them?. Il attach the datasheet of FM receiver too 

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I prefer using the more basic routines for I2C. Byte I2C interface is quite simple: After setting up the component and starting it you use

   

    I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
    I2C_MasterWriteByte(Value);                // Write to register
    I2C_MasterSendStop();                    // End of transaction

   

When you want to read from a device you use (example for reading two bytes

   

    I2C_MasterSendStart(DeviceAddress,I2C_READ_XFER_MODE);    // Initialize a transaction for writing
    I2C_MasterReadByte(I2C_ACK_DATA);            // Read from register
    I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register, last byte is usually NAKed
    I2C_MasterSendStop();                    // End of transaction

   

Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.

   

Bob

Thank you very much!!..

   

Il implement this and try..

0 Likes