atxmega32 USART using DMA not working?? :(

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

I have successfully done USART via DMA using UC3A devices... Now wanted to implemented the same in my xmega project.

Well after translating the framework codes and from AVR1510 app notes I still am failing to produce lines on my hyperterminal.

so far I have the following:

//this function is called from main
void DMA_Init(void)
{
   sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_DMA);
   sleepmgr_lock_mode(SLEEPMGR_IDLE);
	
   //Reset DMA controller just to make sure everything is from scratch
   DMA_CONT->CTRL = DMA_RESET_bm | DMA_ENABLE_bm;
}
//this function called from usart init function
void DMA_DebugChannelInit(void)
{
   //setup DMA for Debug printing (usart) channel
   DMA_CH_DEBUG->CTRLB &= ~(DMA_CH_ERRINTLVL_gm |
                            DMA_CH_TRNINTLVL_gm);
   			   
   DMA_CH_DEBUG->CTRLA = DMA_CH_BURSTLEN_1BYTE_gc;
   DMA_CH_DEBUG->TRFCNT = 0;
	
   DMA_CH_DEBUG->ADDRCTRL = DMA_CH_SRCRELOAD_TRANSACTION_gc| 
                            DMA_CH_SRCDIR_INC_gc  //reload address mode setups
			    DMA_CH_DESTRELOAD_NONE_gc |
                            DMA_CH_DESTDIR_FIXED_gc;	

   //setup the DMA source addresses
   DMA_CH_DEBUG->SRCADDR0 = (unsigned long)(void *)DMA_DebugPrintBuf;
   DMA_CH_DEBUG->SRCADDR1 = (unsigned long)(void *)DMA_DebugPrintBuf >> 8;
#ifdef CONFIG_HAVE_HUGEMEM
   DMA_CH_DEBUG->SRCADDR2 = (unsigned long)(void *)DMA_DebugPrintBuf >> 16;
#else
   DMA_CH_DEBUG->SRCADDR2 = 0;
#endif

   //setup the DMA destination addresses
   DMA_CH_DEBUG->DESTADDR0 = ((unsigned long)(void *)&USART0->DATA);
   DMA_CH_DEBUG->DESTADDR1 = ((unsigned long)(void *)&USART0->DATA) >> 8;
#ifdef CONFIG_HAVE_HUGEMEM
   DMA_CH_DEBUG->DESTADDR2 = ((unsigned long)(void *)&USART0->DATA) >> 16;
#else
   DMA_CH_DEBUG->DESTADDR2 = 0;
#endif

   DMA_CH_DEBUG->REPCNT = 0;	//no repeat of block transfer
   //DMA_CH_DEBUG->CTRLA |= DMA_CH_SINGLE_bm;	//single short burst length
	
   DMA_CH_DEBUG->TRIGSRC = 0x00;     //USART0_DMA_TRIGGER;
   DMA_CH_DEBUG->CTRLA |= DMA_CH_ENABLE_bm;    //enable the transmission channel	
}

//inline function for starting the debug port buffer transmit
extern inline void DMA_DebugChannelStartTx(unsigned short len)
{
   //Setup the transfer count register so transmission can start.
   DMA_CH_DEBUG->TRFCNT = len;
   DMA_CH_DEBUG->CTRLA |= DMA_CH_TRFREQ_bm;		//request new transfer
}

//Has the dma debug channel finished transmitting?
extern inline unsigned char DMA_DebugChannelBusy(void)
{
   return (DMA_CH_DEBUG->CTRLB & DMA_CH_CHBUSY_bm);	
}

//My usart write function is as follows:

void UsartSendString(char *str)
{
	//while(*str)
	//	usart_putchar(USART0, *str++);
	while(DMA_DebugChannelBusy());		//wait while already transmitting previously
	unsigned char *DebugPortTxBufPtr = DMA_DebugPrintBuf;
	while(*str)
	{
		*DebugPortTxBufPtr++ = *str++;
	}
	//Start the transmission up, up to a given length, on the buffer
	DMA_DebugChannelStartTx(DebugPortTxBufPtr - DMA_DebugPrintBuf);
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no one has any says?

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

For 1 thing, you're not doing the software reset correctly . RTM AGAIN on that, and you also need to wait in a loop until the reset bit clears .

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

according to datasheet you do DMA_CH_DEBUG->CTRLA |= DMA_CH_TRFREQ_bm; in order to request a new transfer... which is what my function above is doing....

Which reset bit are you talking about? I didnt see any mention of a wait on reset in the datasheet....

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

Oh I see see....in regards to reset..also it must not be done at the same time as setting enable.... I am going to try that...

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

Nupp still no good...

I did the following in my DMA init function:

DMA_CONT->CTRL = DMA_RESET_bm;
while(DMA_CONT->CTRL & DMA_RESET_bm);
DMA_CONT->CTRL |= DMA_ENABLE_bm;
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I haven't tried DMA at all yet, but I'd look at any threads here that may show proper setup of it and maybe Atmel has a working A.N. using UART with DMA . I got the reset info from looking at one of their DMA A.N. setup code .

Does the uart code work by itself ?

Maybe here :

https://www.avrfreaks.net/index.p...

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

hhm... I give up! It doesnt work for me....

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

I don't see you setting up the USART in SPI master mode and it's REQUIRED .You've redefined the DMA registers so no one can tell which DMA channel you're really setting up .

1Byte_Burst * ( DMA_CH_DEBUG->TRFCNT = 0; )

= 0 bytes sent in a block ... Somebody school me if I'm wrong .

Edit: Alright then, TRFCNT = 0 means 64 KB transfer .

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

Last Edited: Thu. Nov 17, 2011 - 08:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi my definitions as follows:

#define DMA_CONT		(&DMA)
#define DMA_CH_DEBUG	(&DMA_CONT->CH0)

The TRFCNT is set to at the initialization as I dont expect to send anything at the initialization time.

When there is a need to send something I call this function (as I have shown above earlier):

extern inline void DMA_DebugChannelStartTx(unsigned short len)
{
   DMA_CH_DEBUG->TRFCNT = len;
   DMA_CH_DEBUG->CTRLA |= DMA_CH_TRFREQ_bm;   //request new transfer
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What about the usart and SPI thingy I wrote about ? Have you tried simulating all this ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

Last Edited: Thu. Nov 17, 2011 - 06:29 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hhm.. where does it say I have to use usart in SPI mode? I dont need to use spi mode... I want to use plain usart mode :(

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

I'm sorry about that, I was thinking of yours and another thread . I must've mixed them up .

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

Have you tried simulating all this ? So you want manual triggering for EACH byte, according to the code . How about trying trigger on data register empty ? For 'A3 series the syntax is USARTxy, like USARTC0 . Did you rename to ' USART0 ' ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

I dnt know how to use simulatino using avrstudio5 :( tried to use it in the past...not a sounder user of a debugger.

I have defined my USART0 to be USARTE0.
I trigger on block transfer. Each block size is defined by the TRFCNT register. So the software trigger should trigger a block transfer. I dont get any bytes sent so far.. :(

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

Quote:
I dnt know how to use simulatino using avrstudio5
AS5, YUCK ( for now ) ! I've read here that AS4 and AS5 can be on the same computer, so I'd try that . Simulating with AS4 is easy . Also, if I were you I'd simulate the AVR1510 code exactly as written . Get that working, then try your own thing .

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

Last Edited: Thu. Nov 17, 2011 - 08:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

lol i have AS4...I stopped using it long ago in favor of AS5...so much better and useful features in it!
hhm...I will try AS5 simulation then...is this where u can see all the registers being toggled and stuff?

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

Quote:

.so much better and useful features in it!

Only if/when they work!
Quote:
is this where u can see all the registers being toggled and stuff?

Correct - if you've ever used JTAG, debugWire or any real on chip debugger then it's just the same except that the silicon is "virtual".

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

hi all

i'm working on xmega UART Communication with PC

i implemented a GUI to send and receive data from the UART using java (the code is attached) (pc side)

on the xmega side, i want to read data sent from usart using DMA controller but i don't have any idea how to use DMA controller (i don't find any example well commented) and how to know if there is data available. (notify that data is availbe)

for example :

 

if (InputStreamavailable()>0)

read data()

 

could any one help me on this please

Attachment(s):