NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » TWI hang up
October 10, 2011 by esoderberg |
Noter, I have a program using a version of your TWI code communicating at 400kHz between two 328p (one as dedicated Master) as well as with a L3G4200D gyro slave device on the same bus. All is well and good, runs very reliably. I also have a 328p communicating with an AM4096 magnetic encoder slave device. All is well there too. However, when I put all of them together on the same bus and try to communicate with them within the same program using the same supporting functions, the code hangs almost immediately. Tried reducing bit rate and tweaking pull up resistors to no avail. All the SCL/SDA lines are relatively short. Some times it seems to hang on the
line in the TWI interrupt function, but even if this line is removed the code still hangs with all three slaves(and still runs fine until I add the AM4096 into the mix with the 328 and gyro). Eric |
---|---|
October 12, 2011 by hevans (NerdKits Staff) |
Hi esoderberg, Sounds like you covered most of the possibilities here, so I'm guessing there is some subtle bug in the integration of the code. I believe the TWI interface is an addressable interface, could it be that the addresses for your devices are colliding, and causing all the devices to answer at the same time? There could be a weird interaction happening with the interrupt handler code. Are you trying to print stuff out inside your interrupt handlers? This will often cause the handlers to run too slow for the devices. Did you by any chance make your interrupts interrupt-able? This could cause you to run out of memory fairly quick if you keep interrupting interrupts. Humberto |
October 31, 2011 by esoderberg |
Humberto, I guess I'm conditioned by the myriad of mistakes I make along the way for most of my little projects to assume that any IC I'm working with is OK and if something is not working it must be a wiring/circuit mistake or a programming error. However, in this case, after much troubleshooting and gnashing of teeth, it turns out the sample IC I got was the wrong one. After describing the problem to RLS, they sent me another sample and everything is now running exactly as it's supposed to with all components on the TWI bus together. Eric |
November 01, 2011 by Ralphxyz |
Thanks for posting that mishap Eric, that is a really important lesson! Ralph |
Please log in to post a reply.
Did you know that a motor is harder to turn when its terminals are shorted together? Learn more...
|