Xmega TWI Interrupt Driven

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All,

 

I am currently trying to write a small interrupt driven Master TWI library for the ATxmega16A4u. The current issue that I am facing is my ISR is not firing off. After I write the address byte the WIF and CLKHOLD are high while RXACK is low. The BUSSTATE is 0x02 which I believe means it is the owner of the bus. To my knowledge this state means that I have received an ACK from the slave device, but the ISR code does not get run. I have enabled global interrupts sei() as well. I can post code if that would help. I also tried the following library as well adding in an sei() in main with the same results. The board is a custom board made not by me, I can find out more about it if that may be the issue. I am hoping I am just forgetting something dumb.

This topic has a solution.
Last Edited: Fri. Jun 30, 2017 - 05:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would start with the Atmel App Note.  e.g. AVR1308.   Develop from there.

Alternatively stick with polled access.   The Xmega TWI works pretty well.

 

The "library" in your link appears to be a work in progress.   With no examples or test code.

It looks quite "nice" but it would seem safer to use an App Note.

 

There might even be some Atmel "ASF" or "Start" project.    However,  I find most of these too convoluted.   The traditional App Notes are easier to follow.

 

Note that Xmegas are fairly identical.   i.e. A1 code should work on A4, A3, B#, C#, E# chips.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi David,

 

Thanks for the reply, I had seen that document as well as the state diagram in the manual for the xmega16A4U. The only thing that I have possibly not understood is what is to be done after receiving an ACK from the slave? My understanding was that the interrupt would fire, but this could very well be incorrect. You are correct about the "library" posted, I dug that up from an older post on this forum I believe so I thought I would give it a shot. I have read here and there to not use ASF, as well from a colleague of mine that has done some mcu dev, so I have tried not to use it, but it may be worthwhile just to check that it works and that my code is the problem. Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As well as sei() did you enable the various interrupt levels? I can't remember if that register is change protected too.

 

My TWI code is here: https://github.com/kuro68k/xmega...

 

The interrupt driven stuff is not well tested, but the polling code is and works well. Might give you some hints. The Atmel driver is a bit obfuscated but also offers useful hints (AVR1308).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mojo-chan wrote:

My TWI code is here: https://github.com/kuro68k/xmega...

 

That is the "library" that is referenced in my original post wink

 

mojo-chan wrote:

As well as sei() did you enable the various interrupt levels? I can't remember if that register is change protected too.

 

 

If you are referring to  TWIC.MASTER.CTRLA then yes I set it to  

TWIC.MASTER.CTRLA = TWI_MASTER_INTLVL_MED_gc | TWI_MASTER_RIEN_bm | TWI_MASTER_WIEN_bm | TWI_MASTER_ENABLE_bm;

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

mojo-chan wrote:

As well as sei() did you enable the various interrupt levels? I can't remember if that register is change protected too.

 

Actually I think you are referring to PMIC.CTRL register and no I did not... I think this is the problem thank you for the assistance.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just to wrap this up, that was the problem I had not set the PMIC.CTRL register enable the correct interrupt levels. Thank you both for your help.