PDCA for TWI in AT32UC3A series

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

I've had no real trouble getting the PDCA working correctly with USARTs and SPI, both transmit and receive. But for the life of me, I'm not figuring out what needs to happen to use it with TWI.

First of all, the datasheet (page 228, section 24.11.1 and 24.11.2) talks about setting and checking handshaking bits in the PDC module (TXTEN, RXTEN, "end TX flag", "end RX flag", TXDIS, RXDIS) that simply don't seem to exist in the register documentation.

Second, for TWI receives, the datasheet talks about setting up the PDCA transfer size for size-1. (Datasheet's emphasis.) Does this actually mean that the PDCA transfer size needs to be 1 byte less than the total number of data bytes (presumably, excluding addressing) that I expect to transfer? Does that mean, if I were writing a driver that is meant to be able to deal with variable-length transfers, I would have to treat the case of a 1-byte transfer specially, and perform that transfer using polling or interrupts instead of DMA?

Finally, do I need to do anything special to kick off a TWI transfer using PDCA? Or does the simple act of activating the PDCA channel automatically trigger the TWI module to start the transmission?

Can anybody here who's successfully worked with TWI using the PDCA give me some pointers?

Thanks,
Luke

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

With the thought that examples are always better than explanations, I've attached some i2c DMA code of mine.

I wouldn't recommend using the code directly, as it's got a lot of application specific stuff in it (ability to use both I2C ports on the UC3A3, enable lines for external i2c hub chip, etc). It should serve nicely as a DMA+I2C reference, though.

setup_transaction() is the function that does the DMA and I2C/TWI register setup. Line 106 in i2c.c is where things start to happen.

Hope it helps,
Jeff

Attachment(s): 

Jeff Nichols

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

pixel2001n wrote:
With the thought that examples are always better than explanations, I've attached some i2c DMA code of mine.

I wouldn't recommend using the code directly, as it's got a lot of application specific stuff in it (ability to use both I2C ports on the UC3A3, enable lines for external i2c hub chip, etc). It should serve nicely as a DMA+I2C reference, though.

setup_transaction() is the function that does the DMA and I2C/TWI register setup. Line 106 in i2c.c is where things start to happen.

Hope it helps,
Jeff

Jeff (pixel2001n), can you post your code that defines "I2C_A_PDCA_IRQ", found in i2c.c? I'm having trouble selecting the right PDCA IRQ and PDCA channels in my own project? Is there specific values that should be used for PDCA IRQ's?

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

These should be the relevant defines (edited for tabs):

#define I2C_A_TWIM (&AVR32_TWIM1)
#define I2C_A_TWIM_IRQ AVR32_TWIM1_IRQ
#define I2C_A_PDCA_IRQ AVR32_PDCA_IRQ_0
#define I2C_A_PDCA_CHANNEL 0
#define I2C_A_PDCA_TX_PID AVR32_PDCA_PID_TWIM1_TX
#define I2C_A_PDCA_RX_PID AVR32_PDCA_PID_TWIM1_RX
#define I2C_A_SDA_PIN AVR32_TWIMS1_TWD_0_PIN
#define I2C_A_SDA_FUNCTION AVR32_TWIMS1_TWD_0_FUNCTION
#define I2C_A_SCL_PIN AVR32_TWIMS1_TWCK_0_PIN
#define I2C_A_SCL_FUNCTION AVR32_TWIMS1_TWCK_0_FUNCTION

#define I2C_B_TWIM (&AVR32_TWIM0)
#define I2C_B_TWIM_IRQ AVR32_TWIM0_IRQ
#define I2C_B_PDCA_IRQ AVR32_PDCA_IRQ_1
#define I2C_B_PDCA_CHANNEL 1
#define I2C_B_PDCA_TX_PID AVR32_PDCA_PID_TWIM0_TX
#define I2C_B_PDCA_RX_PID AVR32_PDCA_PID_TWIM0_RX
#define I2C_B_SDA_PIN AVR32_TWIMS0_TWD_0_0_PIN
#define I2C_B_SDA_FUNCTION AVR32_TWIMS0_TWD_0_0_FUNCTION
#define I2C_B_SCL_PIN AVR32_TWIMS0_TWCK_0_0_PIN
#define I2C_B_SCL_FUNCTION AVR32_TWIMS0_TWCK_0_0_FUNCTION

Let me know if there's anything else you need.

Jeff Nichols

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

I am working on UC3A0512.... I am trying to get my TWI use the PDCA interface... I have got the transmit working. But Receive does not seem to be working? :(

In order to transmit I just set the tcr value to the transmit length and enable the transmit pdca channel. I do the same for recieve channel as well. But I dont see any receive (repeated start) actions...

Do I have to do anything special for receive?

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

I know I'm replying to a 4 years old thread... but there aren't really a lot of conversations about I2C / TWI with DMA / PDCA around here, and I was about to ask exactly the same questions so I thought why not improving an already existing topic, instead of adding a new one and scattering the info?

Also it seems that the attachments from user 'pixel2001n' were modified at some point, because they don't seem to really use PDCA.

So the two questions are:

lfmorrison wrote:
for TWI receives, the datasheet talks about setting up the PDCA transfer size for size-1. (Datasheet's emphasis.) Does this actually mean that the PDCA transfer size needs to be 1 byte less than the total number of data bytes (presumably, excluding addressing) that I expect to transfer? Does that mean, if I were writing a driver that is meant to be able to deal with variable-length transfers, I would have to treat the case of a 1-byte transfer specially, and perform that transfer using polling or interrupts instead of DMA? Finally, do I need to do anything special to kick off a TWI transfer using PDCA? Or does the simple act of activating the PDCA channel automatically trigger the TWI module to start the transmission?

 

lfmorrison wrote:
Finally, do I need to do anything special to kick off a TWI transfer using PDCA? Or does the simple act of activating the PDCA channel automatically trigger the TWI module to start the transmission?

Last Edited: Tue. Mar 15, 2016 - 11:09 PM