View previous topic :: View next topic |
Author |
Message |
andrew007
Joined: 27 Feb 2023 Posts: 8
|
|
Posted: Tue Mar 07, 2023 9:05 am |
|
|
Ttelmah wrote: | I think what was peculiar, was the decision when designing I2C, to put the
R/W bit at the bottom of the address field. It could have been put at the
top just as easily, and if so the addresses wouldn't have the issue of having
to be doubled when used in the byte... |
it would have been better, actually |
|
|
Gordon23
Joined: 17 Feb 2024 Posts: 6 Location: UK
|
I2C 7 Bits - Direction |
Posted: Thu Feb 29, 2024 2:26 am |
|
|
Hi,
I know this is an old topic, but i came across it, and was a bit confused.
The device in quetion has a 7 bit address followed by a direction bit.
I understand that the PIC uses 8 bits and in order to talk to the device the address needs to be shifted.
But - in the code suggested:-
#define SHT40_BASE_ADDR 0x88
#define SHT4X_CMD_MEASURE_HPM 0xFD
//================================
void main(void)
{
unsigned int8 wData[1] = SHT4X_CMD_MEASURE_HPM;
unsigned int8 rData[6] = {0};
ack = i2c_transfer_out(SHT40_BASE_ADDR, wData, 1);
.
.
.
ack=i2c_transfer_in(SHT40_BASE_ADDR, rData, 6);
.
.
.
while(TRUE)
{
//TODO: User Code
}
}
How would the device know if it is a read or write? The address being sent for transfer in/out is the same?
Can someone explain for me?
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Feb 29, 2024 2:52 am |
|
|
It's hidden from you when using i2C_transfer.
In these commands the read bit is automatically set for address for the
restart the 'in' command.
Normally (if you use the manual commands instead), you have to set the
read bit for a read command yourself. |
|
|
|