ATXMega32E5 TWIC initialization problem (SOLVED)

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Folks,

 

I'm trying to get a LED ring light working.  Basically, I have an ATXMega32E5 that decodes three rotary encoders and sends data to two TLC59116 16 channel LED drivers via I2C.  The encoders and machine state is working correctly, but the TWI is fighting me tooth an nails.

 

While debugging the TWI initialization code and stepping through it, I saw something VERY interesting.  Pictures first:

 

 

When this screen capture was taken, I had just stepped through I2C_init() and am sitting on line 81.  This SHOULD have configured my baud rate for 1Mhz (line 73), put the bus in idle mode (line 74), enabled Fast Mode Plus (Line 75, which enables 1 MHz operation), enabled interrupts for read and write as well as enabled TWI Master (Line 76), cleared CTRLB and CTRLC (Lines 77 and 78), then cleared any status flags (Line 79).

 

The interesting part was when I looked at the TWIC register AFTER stepping through this:

 

 

Everything, and I mean EVERYTHING is set to 0x00 even AFTER it was initialized.  I stepped through it a couple of times to verify and it never initializes anything.  The rest of the initialization functions are working correctly and I can see the registers being updated correctly as I walk through them (clock, PMIC, board I/O, etc.).  But TWIC just sites there and does NOTHING.

 

My first hack was "Did I set the wrong device???" but it was set to the ATMEGA32E5 and the device ID is correct when I connect my debugger to my board (also set as ATMEGA32E5 on PDI).  I then hit the datasheet and verified that TWIC on this device should be at 0x0480 which is what the iox32e5.h header files says it SHOULD be at.

 

And at this point (literally while typing this post out...), my brain starts to wake up!  Brain: "You know, it is almost acting like it is asleep!  HEY!  What if it has been powered off???  I did use that Atmel START to configure this and I DID configure sleep...  But why would it disable the ONE interface on the board I included a driver for???"  So I look at sleep.c and find this:

 

When I first glanced at this, I ASSUMED (yes, I know...) that this was ACTIVE high, meaning if a "1" was set, the device was ACTIVE.  So, a quick double check of the datasheet shows SLEEP is active high, meaning it is powered OFF if a bit is set high...  So, even though I told START I was using TWI (and nothing else other than some pin configurations), it turned everything on EXCEPT for my TWI interface.

 

Needless to say, flipping the "1" and "0" above got my TWI interface responding to configuration writes.  Now maybe I can get the app working...

 

And just for the record, I went ahead and posted this just in case anyone else has done this to themselves...  And I kind of had a lot invested in this post at this point! ;)

 

 

 

 

Clint