Author Topic: Confused about how this I2C read works  (Read 7097 times)

0 Members and 1 Guest are viewing this topic.

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Confused about how this I2C read works
« on: February 25, 2013, 09:39:22 am »
I have an i2c master which writes to a slave (controlling the display) and reads from the same slave getting the button presses.

In idle mode the masters reads every 0.5 seconds or so and receives the following

Quote
S 01000111 0 00000001 0 00000001 0 P
Read from address: 0x23 Number of Bytes: 2
Byte 1: 0x01
Byte 2: 0x01

Pressing a button causes a read instantly giving similar to below
Quote
S 01000111 0 00000100 0 10000010 0 10010001 0 00000000 0 00000100 0 P
Read from address: 0x23 Number of Bytes: 5
Byte 1: 0x04
Byte 2: 0x82
Byte 3: 0x91
Byte 4: 0x00
Byte 5: 0x04

There is a third line in addition to SDA and SCL which is pulled low during read and write operations, i thought perhaps that the slave was pulling this low when data was available but having disconnected the master and watched this third line it is going low for three 6ms pulses every 0.5 seconds. Pressing a button has no affect on this.

I have successfully managed to write to the slave but not read. I have tried to read both 2 and 5 bytes when the third line goes low. Reading 2 will give me 0x01 0x01 as above but trying 5 will just give me 0x01 0x01 0xff 0xff 0xff with button presses having no affect on  the output.

Any clues how the master might be telling when there is data to be read or what i could try?

Thanks
Chet
Paid Electron Wrestler
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #1 on: February 25, 2013, 12:47:09 pm »
Further testing shows that its the slave that decides when to be read from, the master holding the line low when writing and the slave doing the same for reads.

Using the arduino wire library as read requests need to specify the number of bytes, i this normal practise? Should the master be able to open a request and the slave decide when to stop?
Chet
Paid Electron Wrestler
 

Offline shebu18

  • Frequent Contributor
  • **
  • Posts: 307
  • Country: ro
Re: Confused about how this I2C read works
« Reply #2 on: February 25, 2013, 10:05:58 pm »
Can you give us the model of the slave and master? Exact name. In I2C you have only 2 line, not 3. 3lines sounds more like some sort of SPI.
 

Offline richcj10

  • Supporter
  • ****
  • Posts: 200
  • Country: us
Re: Confused about how this I2C read works
« Reply #3 on: February 25, 2013, 10:06:27 pm »
It really depends on the device. There are EEPROM devices that allow consecutive reads from the device w/o requesting the data.

What chip is it? That would tell forum members more information.
 

Offline richcj10

  • Supporter
  • ****
  • Posts: 200
  • Country: us
Re: Confused about how this I2C read works
« Reply #4 on: February 25, 2013, 10:07:21 pm »
Can you give us the model of the slave and master? Exact name. In I2C you have only 2 line, not 3. 3lines sounds more like some sort of SPI.

It could be a interrupt....
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #5 on: February 25, 2013, 10:21:17 pm »
I'm calling it i2c as not counting the third line it is the same and the display will work with only the data and clock connected.

I don't know the models as I haven't taken them apart (these are in my car) I only have access to the wiring between them.
Chet
Paid Electron Wrestler
 

Offline caroper

  • Regular Contributor
  • *
  • Posts: 193
  • Country: za
    • Take your PIC
Re: Confused about how this I2C read works
« Reply #6 on: February 26, 2013, 01:13:07 am »
"I'm calling it i2c as not counting the third line it is the same and the display will work with only the data and clock connected."

You can't just arbitrarily call it anything based on the number of lines, you may as well call it RS232 as that will work with only 2 lines as well.
Based on your description though I would have to agree that you are using SPI not I2C, as SPI also requires  Clock and a Data lines. The 3rd or more lines in SPI are Chip Select Lines when you have more than one device on the bus.

Whilst electrically the same SPI, I2C and RS232 are all Software Protocols as well as a Hardware Standard.
To really know what is happening you need to know what the Protocol is and therefor what Signals and Timing to expect on the lines, hence we can't help you unless you state the Protocol used.

Cheers
Chris

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #7 on: February 26, 2013, 01:50:34 am »
When i sat its the same i mean the protocol is the same, aside from the 7kHz clock speed which i put down to being used because of the distance between the devices.

I'll take the slave apart and see if i can find anything inside
Chet
Paid Electron Wrestler
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #8 on: February 26, 2013, 03:23:26 am »
Inside the slave is some Sagem ic (AFRHEUT0200 HD6433834822H) that isn't throwing up any results on google and a few other bits - voltage reg, inverter, discretes etc
Chet
Paid Electron Wrestler
 

Offline richcj10

  • Supporter
  • ****
  • Posts: 200
  • Country: us
Re: Confused about how this I2C read works
« Reply #9 on: February 26, 2013, 06:29:42 am »
Is this in a car?
Could it be CAN?
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #10 on: February 26, 2013, 06:36:53 am »
Yes, its in a car. It is the radio (master) and the display/wheel controls(slave). I tried doing this on my old car which had a very similar setup (3 wires, 2 of which followed the i2c protocol)

The car is a 2002, it has a primitive CAN bus but the radio setup is isolated. The later versions of my car did switch to CAN for the radio.
Chet
Paid Electron Wrestler
 

Offline richcj10

  • Supporter
  • ****
  • Posts: 200
  • Country: us
Re: Confused about how this I2C read works
« Reply #11 on: March 01, 2013, 06:08:12 pm »
It is probably CAN. It may not be at CAN voltages. That means it is not using transceivers.  Do you have a scope? Logic analyzer?
 

Offline AndreasF

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: gb
    • mind-dump.net
Re: Confused about how this I2C read works
« Reply #12 on: March 01, 2013, 06:20:32 pm »
Further testing shows that its the slave that decides when to be read from, the master holding the line low when writing and the slave doing the same for reads.
...

That doesn't really sound like 'slave' behaviour (unless I misunderstood your description). You can have multiple masters in an I2C bus, if what you have is indeed an I2C protocol.
my random ramblings mind-dump.net
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #13 on: March 01, 2013, 09:24:04 pm »
It is probably CAN. It may not be at CAN voltages. That means it is not using transceivers.  Do you have a scope? Logic analyzer?

Yes, both. 5v logic levels and the logic analyser decodes it as i2c. Writing works fine using a standard i2c library (only modified to use the 7kHz clock)
Chet
Paid Electron Wrestler
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #14 on: March 01, 2013, 09:31:36 pm »
Further testing shows that its the slave that decides when to be read from, the master holding the line low when writing and the slave doing the same for reads.
...

That doesn't really sound like 'slave' behaviour (unless I misunderstood your description). You can have multiple masters in an I2C bus, if what you have is indeed an I2C protocol.

When i posted originally i wasn't aware that it was the slave (i'll stick with that term for the minute!) that was pulling the third line low. It does appear the the reads are initiated from the master following the i2c protocol but the timing of the reads is determined by the slave.

The thing i find unusual is the varying number of bytes sent from the slave as it was my understanding that the master determined the amount read whereas here it would have no prior knowledge of whether it had five bytes to read. I don't think this will matter for me reading button presses anyway but i am curious.
Chet
Paid Electron Wrestler
 

Offline AndreasF

  • Frequent Contributor
  • **
  • Posts: 251
  • Country: gb
    • mind-dump.net
Re: Confused about how this I2C read works
« Reply #15 on: March 01, 2013, 09:44:19 pm »
Well, the first byte that's being sent (by the slave) seems to indicate the number of bytes that are available to read (from the slave), so all the master needs to do is send the slave address in read mode, wait for the first byte from the slave, and continue to read according to this first byte.
my random ramblings mind-dump.net
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #16 on: March 01, 2013, 10:05:49 pm »

Having looked into the library I think i see where I've gotten mixed up. With the arduino you start a read specifying the address and number of bytes. These are then read from the buffer. I was mistaken in thinking the master sent the number of bytes to the slave.

Yes the first byte returned will give me an indication of whether I have a button press to read.

Chet
Paid Electron Wrestler
 

Online free_electron

  • Super Contributor
  • ***
  • Posts: 6922
  • Country: us
    • SiliconValleyGarage
Re: Confused about how this I2C read works
« Reply #17 on: March 02, 2013, 09:36:19 am »
if they use 3 wire it could be C-Bus... that is almost i2c...
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 

Offline ve7xen

  • Frequent Contributor
  • **
  • Posts: 644
  • Country: ca
    • VE7XEN Blog
Re: Confused about how this I2C read works
« Reply #18 on: March 02, 2013, 05:16:19 pm »
Is this maybe an (ab)use of I2C clock stretching? The master could be initiating the read immediately after having received some data, with the slave stretching the clock until an event happens, when it sends the requested data to the master. This feature is designed to allow the slave to throttle commands if the master is sending them too quickly for it to handle, but I suppose it could be used as a crude form of interrupt as well.

I'm not sure if the AVR TWI peripheral supports clock stretching (check the manual, this is an oft-omitted feature), but I'd bet the Arduino bit-banged library does not. I believe Peter Fleury's bitbanged I2C library does, however.
73 de VE7XEN
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 5812
Re: Confused about how this I2C read works
« Reply #19 on: March 02, 2013, 06:15:59 pm »
Inside the slave is some Sagem ic (AFRHEUT0200 HD6433834822H) that isn't throwing up any results on google and a few other bits - voltage reg, inverter, discretes etc
I think you misread the part# as that is probably the HD6433834S - Hitachi (now Renesas) H8 microcontroller. The datasheet does not explicitly mention CAN or I2C but there is a UART peripheral capable of different transfer modes. Or they could be bit-banging I2C/CAN...
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #20 on: March 03, 2013, 06:55:43 am »
I done some more testing, after a write the slave will pull the third line low waiting for a read. If it doesn't get one it will release the line and try twice more. If i initiate a read when its pulled low i can read the data, either the 2 or 5 bytes depending on whether the buttons are pressed. Strangely although reading them fine the arduino is is not sending an ACK for the last byte which causes the slave to try to send everything again (twice more, as above) so if i read a button press i will actually see it three times.

Inside the slave is some Sagem ic (AFRHEUT0200 HD6433834822H) that isn't throwing up any results on google and a few other bits - voltage reg, inverter, discretes etc
I think you misread the part# as that is probably the HD6433834S - Hitachi (now Renesas) H8 microcontroller. The datasheet does not explicitly mention CAN or I2C but there is a UART peripheral capable of different transfer modes. Or they could be bit-banging I2C/CAN...

I didn't take the display apart again (it has one of thos super thin ribbon cable things attaching the LCD that i don't want to break) but the package seems to match up. Good spot!
Chet
Paid Electron Wrestler
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #21 on: March 03, 2013, 09:14:24 am »
Some logic analyser screen grabs

Here is a read with the original master and slave



And here is one with me as master

Chet
Paid Electron Wrestler
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 5812
Re: Confused about how this I2C read works
« Reply #22 on: March 04, 2013, 12:51:36 am »
Since this might not really be I2C you may be violating some timing requirement.
 

Offline richcj10

  • Supporter
  • ****
  • Posts: 200
  • Country: us
Re: Confused about how this I2C read works
« Reply #23 on: March 04, 2013, 07:44:18 am »
Some devices don't care or want to see the NAK.
Other IC's really care about seeing the ACK. 
Try that first.
 

Offline TerminalJack505

  • Super Contributor
  • ***
  • Posts: 1205
  • Country: 00
Re: Confused about how this I2C read works
« Reply #24 on: March 04, 2013, 10:06:21 am »
The Arduino library will send a NACK when it has received the last byte.  This is normal.  It's supposed to tell the slave that the master is done reading. 

You might be able to emulate the behavior you are seeing by calling Wire.requestFrom() with a quantity parameter value that is larger than the number of bytes you actually expect.

If that doesn't work AND you actually need that behavior then you might just try bit-banging the I2C bus yourself.

The attached ZIP has the code from a simple little project I did with an ATtiny2313, which has no native I2C support.  I'm pretty sure the code for bit-banging the I2C bus was taken pretty much as-is from an Atmel app note.  I likely just wrapped their code in a C++ class.
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #25 on: March 04, 2013, 11:02:35 am »
Ok well that makes perfect sense then. I will try requesting 6 bytes (max is normally 5) and see if that satisfies the slave. Aside from it causing the slave to reattempt a send (i.e. pull the line low to start a read) there is no negative affect on what i'm trying to do. Once i have completed a read i can ignore the others in code or pull it low myself which should stop it.

At this point i don't see a need to bit-bang. There is a couple of software i2c libraries about - i have been able to write to the display using an Attiny85
Chet
Paid Electron Wrestler
 

Offline man-x86

  • Newbie
  • Posts: 4
  • Country: de
Re: Confused about how this I2C read works
« Reply #26 on: February 13, 2018, 07:44:59 am »
It seems that I'm very late on this topic, but there's not much information available on this kind of hardware. I'd like to thank Chet T16 for showing that it is possible to write some user text on the LCD ;).

I also have a Tuner List radio, and it required some reverse engineering to understand how the display works:
https://imgur.com/gallery/AlMld

And here's an obvious proof that it worked:

I still have to figure out how to read the data from buttons under the steering wheel, but that shouldn't be too hard once the this step has been made.
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #27 on: February 13, 2018, 08:01:04 am »
It seems that I'm very late on this topic, but there's not much information available on this kind of hardware. I'd like to thank Chet T16 for showing that it is possible to write some user text on the LCD ;).

I also have a Tuner List radio, and it required some reverse engineering to understand how the display works:
https://imgur.com/gallery/AlMld

And here's an obvious proof that it worked:

I still have to figure out how to read the data from buttons under the steering wheel, but that shouldn't be too hard once the this step has been made.
Good to see this still doing the rounds.

From what I recall to read the buttons you must do an i2c read from the display and the first byte tells you if there are any further bytes to be read. If it's non zero the following bytes tell you what button is pressed. Using the arduino ide you must send the number of bytes to read first but as the length varies I sent a fixed value, 5 I think, and discarded the data if the first byte was zero.

I may still have access to my old notes

Sent from my SM-G925F using Tapatalk

Chet
Paid Electron Wrestler
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #28 on: February 13, 2018, 08:02:58 am »
Actually I see I covered some of this above now that I reread!

Sent from my SM-G925F using Tapatalk

Chet
Paid Electron Wrestler
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #29 on: February 13, 2018, 08:08:22 am »
From my notes:
Code: [Select]
Volume Up Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x06
Volume Up Hold: 0x47 0x01 0x10 0x49 0x10 0x00 0x86
Volume Down Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x08
Volume Down Hold: 0x47 0x01 0x10 0x49 0x10 0x00 0x88
Pause Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x0A
Pause Hold: 0x47 0x01 0x10 0x49 0x10 0x01 0x0A
Source Right Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x02
Source Right Hold: 0x47 0x01 0x10 0x49 0x10 0x01 0x02
Source Left Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x04
Source Left Hold: 0x47 0x01 0x10 0x49 0x10 0x01 0x04
Bottom Button Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x00
Bottom Button Hold: 0x47 0x01 0x10 0x49 0x10 0x01 0x00
Scroll Up: 0x47 0x01 0x10 0x49 0x10 0x04 0x82
Scroll Down: 0x47 0x01 0x10 0x49 0x10 0x04 0x02
Chet
Paid Electron Wrestler
 

Offline man-x86

  • Newbie
  • Posts: 4
  • Country: de
Re: Confused about how this I2C read works
« Reply #30 on: February 13, 2018, 08:15:54 am »
It seems that I'm very late on this topic, but there's not much information available on this kind of hardware. I'd like to thank Chet T16 for showing that it is possible to write some user text on the LCD ;).

I also have a Tuner List radio, and it required some reverse engineering to understand how the display works:
https://imgur.com/gallery/AlMld

And here's an obvious proof that it worked:
[img]https://i.imgur.com/7FzgPls.jpg[/img_]
I still have to figure out how to read the data from buttons under the steering wheel, but that shouldn't be too hard once the this step has been made.
Good to see this still doing the rounds.

From what I recall to read the buttons you must do an i2c read from the display and the first byte tells you if there are any further bytes to be read. If it's non zero the following bytes tell you what button is pressed. Using the arduino ide you must send the number of bytes to read first but as the length varies I sent a fixed value, 5 I think, and discarded the data if the first byte was zero.

I think I'll figure out by myself during the next rainy weekend, reverse engineering is still plenty of fun.

I see that you also used the Arduino IDE. Did you also had to tweak the Wire library (TWBR = 0xff and TWSR = 0x01) for the unusually slow bitrate?

From my notes:
Code: [Select]
Volume Up Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x06
Volume Up Hold: 0x47 0x01 0x10 0x49 0x10 0x00 0x86
Volume Down Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x08
Volume Down Hold: 0x47 0x01 0x10 0x49 0x10 0x00 0x88
Pause Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x0A
Pause Hold: 0x47 0x01 0x10 0x49 0x10 0x01 0x0A
Source Right Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x02
Source Right Hold: 0x47 0x01 0x10 0x49 0x10 0x01 0x02
Source Left Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x04
Source Left Hold: 0x47 0x01 0x10 0x49 0x10 0x01 0x04
Bottom Button Press: 0x47 0x01 0x10 0x49 0x10 0x00 0x00
Bottom Button Hold: 0x47 0x01 0x10 0x49 0x10 0x01 0x00
Scroll Up: 0x47 0x01 0x10 0x49 0x10 0x04 0x82
Scroll Down: 0x47 0x01 0x10 0x49 0x10 0x04 0x02
Wow, thanks a lot.
 

Offline Chet T16

  • Frequent Contributor
  • **
  • Posts: 522
  • Country: ie
    • Retro-Renault
Re: Confused about how this I2C read works
« Reply #31 on: February 13, 2018, 08:27:45 am »
For some reason I copied the wire library and made a new version to suit the 7kHz speed, not sure why i done that!

I just found this in a text file called notes.txt, may be of use to you

Code: [Select]
When idle - radio writes 0x01 0x11

Reads controls - if no input it receives 0x01 0x01
Chet
Paid Electron Wrestler
 

Offline man-x86

  • Newbie
  • Posts: 4
  • Country: de
Re: Confused about how this I2C read works
« Reply #32 on: February 13, 2018, 08:49:27 am »
I fixed it in a terribly ugly way for the 1st tests, by calling a function after every call to the Wire library (at least every call that I suspect to overwrite those registers).

void conf() {
  TWBR = 0xff;
  TWSR = 0x01;
  //TWCR &= ~(1<<TWEA); // ignore ACK, bad idea
}


I already noticed the constant {0x01, 0x11} writes and {0x01, 0x01} reads, but thanks for adding that.
 

Offline man-x86

  • Newbie
  • Posts: 4
  • Country: de
Re: Confused about how this I2C read works
« Reply #33 on: February 26, 2018, 04:58:44 am »
Interesting, I noticed different values for the controls on my car:
Code: [Select]
    *  Source R: 0x04, 0x82, 0x91, 0x00, 0x01 (press)
    *  Source R: 0x04, 0x82, 0x91, 0x00, 0x81 (hold), but sending 0x41 works as well
    *  Source L: 0x04, 0x82, 0x91, 0x00, 0x02 (press)
    *  Source L: 0x04, 0x82, 0x91, 0x00, 0x82 (hold), but sending 0x42 works as well
    * 
    *  Volume +: 0x04, 0x82, 0x91, 0x00, 0x03 (press)
    *  Volume +: 0x04, 0x82, 0x91, 0x00, 0x43 (hold)
    *  Volume -: 0x04, 0x82, 0x91, 0x00, 0x04 (press)
    *  Volume -: 0x04, 0x82, 0x91, 0x00, 0x44 (hold)
    * 
    *  Pause   : 0x04, 0x82, 0x91, 0x00, 0x05 (press) apparently, no hold feature
    *  OK      : 0x04, 0x82, 0x91, 0x00, 0x00 (press)
    *  OK      : 0x04, 0x82, 0x91, 0x00, 0x40 (hold)
    *
    *  Wheel UP: 0x04, 0x82, 0x91, 0x01, 0x41
    *  Wheel DN: 0x04, 0x82, 0x91, 0x01, 0x01
I didn't check if the values from your car work on my radio, but I assume it would be compatible.

I can manage to capture the keypresses with an MCU although it's a bit messy (it's not the goal anyways).

My final goal is replace the display by a raspi (media center + navigation), and keep the original steering wheel buttons to control the raspi and the original radio (only the volume/pause + forcing the source on AUX).

I managed to go a bit further by controlling the radio from the MCU, but now I got most of the things working, I'll definitely have to rewrite the code properly (I'm adding nops to time properly the MRQ line).


I noticed that some other cars (Renault Laguna 1, Scenic 1) were sold with an early GPS navigation system (Carminat). Thankfully, they reused the same layout on the other cars of that era (Megane 1, perhaps the Clio 2 as well), even though there was no option for a factory navigation system. So that gives plenty of room under the console/dashboard for a raspi + a 5" touchscreen to fit.
 

Offline bson

  • Supporter
  • ****
  • Posts: 1289
  • Country: us
Re: Confused about how this I2C read works
« Reply #34 on: February 26, 2018, 07:58:19 pm »
HD6433834822H
This is probably some variant of the Renesas H8 series uC.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf