Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Synchronize master/slave communication on UART (2xAT91SAM7X)
PostPosted: Thu Mar 29, 2012 6:33 pm 
Offline

Joined: Thu Mar 29, 2012 5:19 pm
Posts: 17
Scenario:
2 AT91SAM7X boards communicate over USART. Master sends request, which has to be answered by slave within 1 ms. Beside the communication purpose, the master also uses the messages as heartbeat: If slave does not answer properly on 5 or more requests, either communication is broken or slave is offline. Therefore, every 1 millisecond a message is sent, regardless whether there is a slave or not.
Packet sizes are fixed (10 byte master -> slave request, 28 bytes for the response). Also, a DMA transfer with fixed frame sizes is used (manual 22.4.2., PDC Receive Counter Register) to keep the communication simple.

Problem:
Consider the master already starting, sending 10 byte packets every milliseconds. During a send, the slave's DMA receiver is started, thus receiving only 5 of 10 bytes total. Next time the master sends 10 bytes, the slave receives the rest of his jittered packets.

Goal:
I'd like to have a timeout, which discards the already received data, if there has not been sent any new data after 100 micro seconds (my timer period).

Question:
In manual 30.6.3.8 I've read about USART's "Receiver Time-out". Is this the right tool for this purpose?
I'd throw an interrupt and then reset DMA transfer counter to restart transfer.
Maybe there's an even easier way to accomplish this "synchronization"?

Thank you for reading,
Paule


Top
 Profile  
 
 Post subject: Re: Synchronize master/slave communication on UART (2xAT91SA
PostPosted: Thu Mar 29, 2012 7:23 pm 
Offline

Joined: Fri Mar 09, 2012 1:34 pm
Posts: 68
Hi Paul!
You are right. Here I give you a snippet of a code to achieve this:

void US1_SetRXTimeout( int timeout )
{
AT91C_BASE_US1->US_RTOR = timeout;
AT91C_BASE_US1->US_CR = AT91C_US_STTTO;
//AT91C_BASE_US0->US_CR = AT91C_US_RETTO;
}


void US1_Irq() __irq
{
AT91_REG channelStatusRegister = AT91C_BASE_US1-> US_CSR;
channelStatusRegister &= AT91C_BASE_US1->US_IMR;

if( channelStatusRegister & AT91C_US_TIMEOUT )
{
//do sth here
}
else if( ... )
{
//.....
}
AT91C_BASE_AIC->AIC_EOICR = 0;
}

The UART time-out can work in two modes:
a) start counting down after receiving first byte (the option you want)
b) start counting down right away - bit AT91C_US_RETTO set high;

Timeout is programmed in units of bits. When the US_RTOR counter reaches 0, the interrupt is triggered.

_________________
Best regards
Przemyslaw Baranski


Top
 Profile  
 
 Post subject: Re: Synchronize master/slave communication on UART (2xAT91SA
PostPosted: Thu Mar 29, 2012 7:56 pm 
Offline

Joined: Sat Oct 30, 2010 6:04 pm
Posts: 784
Using DMA on the receive side, and not being able to handle data loss, or framing issues, looks to be a recipe for failure.

Ideally you want a state machine on the receive side, and a self-synchronizing protocol like SLIP, or HDLC.


Top
 Profile  
 
 Post subject: Re: Synchronize master/slave communication on UART (2xAT91SA
PostPosted: Fri Mar 30, 2012 7:22 am 
Offline

Joined: Thu Mar 29, 2012 5:19 pm
Posts: 17
G'morning :)

Thank you for your replies and examples, przemekbary and CptTitanic!

@CptTitanic: The attempt to handle data loss is to not send a reply or to send specific NACK reply from slave to master. Anyway, the master will retry sending the packet on next time slot (every 1 ms), if he got no positive response on his request from slave.
Using the timeout feature, the slave will be synchronized on 2nd attempt.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: