IIC usage problem
Alan Adams (2486) 1149 posts |
I am trying to use the IIC bus in an rPi and getting confused. I expected I should use the write version of the address to send commands to the interface, or to send data to be transferred to the 1-wire bus. Have I got this wrong, and if so, why? |
Alan Adams (2486) 1149 posts |
I’ve now modified my code to test all 256 addresses (128 read and 128 write) and report responses. DIM data% 20 This returns address 1B valid for read, as expected, no address is valid for write. I’ve tried various values in data% and for the number of bytes there, and get no difference. I’m wondering whether there is a fault in the hardware – it’s an interface board from Sheepwalk Electronics. They only supply software for Linux, and setting that up is more than i want to attempt at the moment. |
Dave Higton (1515) 3526 posts |
I’m reading Maxim’s data sheet for the DS2482-100. If you’ve set AD0 and AD1 both high, the addresses it should respond to are &37 for read and &36 for write, when considered as a byte on the IIC bus – these are of course &1B when shifted right 1. If you request 16 bytes from the read address, is there anything to generate them – or does this leave the DS2482-100 busy, in which case it should not generate an ACK? |
Dave Higton (1515) 3526 posts |
Also: “The DS2482-100 acknowledges valid command codes and expected/valid command parameters. Additional bytes or invalid command parameters are never acknowledged.” |
Dave Higton (1515) 3526 posts |
Looking at the Communication Examples from the data sheet, I don’t think there is ever a case when you can send 16 bytes to the DS2482-100. The operation will always fail with no ACK, it seems to me. |
Alan Adams (2486) 1149 posts |
Thanks for the reply, Dave. My main confusion was that stuffing values into the parameter block, I automatically assumed word sizes, so put the command in byte 0, parameter in byte 4, and said 8 bytes were present. Fixing that has allowed me to scan the addresses successfully, and get at least partway to reading the data register. I’ll start trying to get valid data into that register tomorrow. (Incidentally I am editing the code on the ARMX6, copying it over sharefs to the rpi, and running it via Avalanche. All fine, except when I inadvertently double-click the copy on the ARMX6. So far it doesn’t seem to have upset the ARMX6, which does have several working addresses on IIC bus 0. More care needed I think.) The code so far is: SYS “OS_ReadSysInfo”,14 TO busses REM commands for interface REM interface registers REM commands for 1-wire bus DIM data% 20 FOR I%=0 TO255 PROCsend(writeaddr%,iic_setreadptr%,statusreg%,2) END DEF PROCsend(address%,command%,value%,size%) END DEF PROCwait(secs%) DEF PROCerror |
Alan Adams (2486) 1149 posts |
OK, quite a bit of success, and a brick wall. |
Alan Adams (2486) 1149 posts |
More progress, and another brick wall. I’ve found a datasheet with the search algorithm in C form, and converted it to BASIC. However it starts with a 1-wire reset, and checks for Presence Pulse Detect. This fails to show up, with either of the sensors I’m working on. An Oscilloscope shows that there is activity on the 1-wire bus, but I haven’t yet got a stable enough display to measure the timings. I can say that disconnecting the sensor doesn’t seem to change the pulse pattern or widths. |
Dave Higton (1515) 3526 posts |
Have you set Strong Pull Up? |
Alan Adams (2486) 1149 posts |
No. The data sheet doesn’t suggest that is needed, especially as I’m using the 3-wire connection. There’s a warning against using SPU with the 1-wire-reset, as it can damage the DS2482 chip. |
Alan Adams (2486) 1149 posts |
According to the data sheets, a reset pulse should last a minimum of 480 microsecs (uS). When I test this, the DS2482 issues a burst of activity lasting about 500uS, consisting of a low for 60 uS, high about 6uS, low 60uS, high 6uS, low 6uS, high 60uS, low 60uS, high 6uS, low 6uS, high 60uS, low 6uS, high 60uS, low 60uS, then a long period high until the next reset is sent. |
Rick Murray (539) 13840 posts |
Given that the 3.3V IIC standard came after the 400kHz spec, and that predated the Archimedes (!)… …would there not be an argument for finally supporting it in RISC OS? I hacked my build of RISC OS to do this, so I can confirm it works with:
The CJE stuff and the OLED used on both Pi models. Default settings means I’ve not messed with processor or memory speeds. Everything accessed either by RISC OS directly or via the OS’ IIC calls. As such, I find no sensible reason to keep running the IIC bus at a speed from the early eighties… |
Dave Higton (1515) 3526 posts |
I would certainly support an API to permit setting bus speeds (100kHz, 400kHz, 1MHz) – but, unless and until you can prove that there is zero chance that anyone will ever use an IIC device that will not operate beyond 100kHz, I still believe that the bus speed should default to 100kHz. |
Rick Murray (539) 13840 posts |
There isn’t zero chance, nor will there ever be. It’s extremely unlikely but not impossible. However it doesn’t matter. This will only apply to those SoCs with hardware IIC controllers (not the IOMD bit bashed pins), so as long as the hardware isn’t junk, the slave device is actually able to stall the data rate using a technique called clock stretching. https://www.i2c-bus.org/clock-stretching/ |
Rick Murray (539) 13840 posts |
Aside: Technically, none of the Acorn designed machines ever legitimately had IIC inside them, as the specification required clock stretching (for slower devices) and arbitration (for multiple masters). The implementation in RISC OS supports neither as it has always assumed it’s a single master system for talking to an RTC. It still doesn’t though I can imagine these days the HAL just passes the request on to hardware that does support these things. </pedantic> |
Alan Adams (2486) 1149 posts |
I got a bit confused earlier. The speed change I referred to was that between standard and overdrive on the 1-wire bus. I mentioned 100KHz, bus now realise that applied to the IIC bus. As I’m having to work with both buses here, there is a lot of scope for confusion. It doesn’t alter the fact that the IIC-to-1_wire interface isn’t creating a legal reset pulse. The actual pulse burst is here: |
Alan Adams (2486) 1149 posts |
Cracked that now. The problem was that I was sending the reset command as a data byte to the 1-wire bus. It is in fact a command to the interface which causes it to produce a reset event. It’s such fun working with two (new to me) busses at once. |