- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Solved! Go to Solution.
- Labels:
-
PSoC 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much!!..
Il implement this and try..