Singlewire UART problems on xmega128a1

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

I'm trying to set up a singlewire-UART communication between two xmega128a1 cards. I use one as a master and the other as a slave. I'm sending a testvalue to the slave and when the slave reads the value it sends another testvalue back to the master.

Here's the master code:

while(1)
{
     while( (USART.STATUS & USART_DREIF_bm) == 0 ) {}
        USART.CTRLB = 0x18;   //Enables TX & RX
	Tx_Buf=0x8;           //Test-value
        USART.DATA = Tx_Buf;  //Sends the test value#1
	LEDPORT.OUT=0xF0;     //Light indicators
	USART.CTRLB = 0x10;   //Disables TX

		
    while((USART.STATUS & USART_RXCIF_bm) == 0) {}	
	Rx_Buf=USART.DATA; //Reads test-value #2
	if(Rx_Buf==0xA)   
	LEDPORT.OUT=0xF;  //Light indicators	
}

Here's the slave code:

while(1)
    {
     while ( (USART.STATUS & USART_RXCIF_bm) == 0 ) {}  
     USART.CTRLB = 0x10;  //Enables RX
     Rx_Buf=USART.DATA;   //Reads value from master
     if(Rx_Buf==0x8)    
     LEDPORT.OUT=0xF0;	  //Light indicators	
        
     while( (USART.STATUS & USART_DREIF_bm) == 0 ) {}							                							    
     USART.CTRLB = 0x18;  //Enables TX&RX
     Tx_Buf=0xA;          //Test-value #2   					 
     USART.DATA = Tx_Buf; //Sends test-value #2							
     LEDPORT.OUT=0xF0;    //Light to indicate that the
                          //value have been sent
    }

It doesn't work (obviously), but where is the problem?
The communication works between the two cards (tested it), it's the dynamic which reads and sends the value that doesn't work.

I've added two diodes and a resistance so the hardware shouldn't be the problem either. Also I got a oscilloscope, so I know that the master starts to send. Anyone got a suggestion?

Thanks
Richard

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

TXD and RXD are separate lines. What do you mean about "Single wire UART"?

Ozhan KD
Knowledge is POWER

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

It's like half duplex. RX and TX are connected to each other so they just communicate with one wire, not two which is most common.

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

By connecting TXD to RXD and according to your code, master receives its own data. Verify this by:

Rx_Buf=USART.DATA;
LEDPORT.OUT=Rx_Buf;

PS: Above verification can be done, if all 8 bits of LEDPORT are available.

Ozhan KD
Knowledge is POWER

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

electronic.designer wrote:
By connecting TXD to RXD and according to your code, master receives its own data. Verify this by:

Rx_Buf=USART.DATA;
LEDPORT.OUT=Rx_Buf;

PS: Above verification can be done, if all 8 bits of LEDPORT are available.

Well, yes, but I got a diode and a resistance so the RX won't read itself.

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

I cannot tell anything about your hardware without schematic. Also in your code, the receiver must be enabled before any reception and this is the case for transmitter:

Try this code:
master:

while(1)
{
 USART.CTRLB = 0x08;   //Enables TX
 while(!(USART.STATUS & USART_DREIF_bm));  
 USART.DATA = 0x08;  //Sends the test value#1 
 while(!(USART.STATUS & USART_TXCIF_bm));  
 USART.STATUS=USART_TXCIF_bm;
 LEDPORT.OUT=0xF0;     //Light indicators
 
 USART.CTRLB = 0x10;  //Enables RX
 while(!(USART.STATUS & USART_RXCIF_bm));   
 Rx_Buf=USART.DATA; //Reads test-value #2
 if(Rx_Buf==0xA) LEDPORT.OUT=0xF;  //Light indicators    
} 

slave:

while(1)
{
 USART.CTRLB = 0x10;  //Enables RX    
 while (!(USART.STATUS & USART_RXCIF_bm));     
 Rx_Buf=USART.DATA;   //Reads value from master
 if(Rx_Buf==0x8) LEDPORT.OUT=0xF0;     //Light indicators      
    
 USART.CTRLB = 0x08;   //Enables TX
 while(!(USART.STATUS & USART_DREIF_bm));  
 USART.DATA = 0x0A; //Sends test-value #2
 while(!(USART.STATUS & USART_TXCIF_bm));
 USART.STATUS=USART_TXCIF_bm;  
 LEDPORT.OUT=0xF0;    //Light to indicate that the
                      //value have been sent
} 

Ozhan KD
Knowledge is POWER

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

Schematic:
http://home.no/mainforce/singlewire.png

Thank you, I will give this code a try and give you a feedback on it. Appreciate it alot:)

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

By the way, the slave I'm programming is reference to what's called Position Controller on the picture.

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

Well, I tried the code, didn't help. Hrmf

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

If the line is sometimes driven by the AVR and sometimes it's high-Z while receiving how do the two ends synchronize things so they aren't both driving the line at the same time (possibly in opposite directions).

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

Your hardware does not seem to work correct. How did you connect XMEGA to 5v bus and what is the function of the diode in schematic?

Ozhan KD
Knowledge is POWER

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

clawson: Thanks for the input. I tried setting the slave in a "receive"-mode, which basicly means he waits for an value from the master. When the value is received he then sends out a new value to the master. The master is then in a recieve-mode and won't do nothing until it gets a value back. Didn't work:\

electronic.designer: I use an external 5v supply. The diode is there to prevent information being sent from Tx when the Rx is reading. The Tx is default high(Vcc I think) and would interrupt the Rx reading if there weren't a diode there(not 100% sure).

Thanks for the inputs Ü

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

I don't understand the 5 volts. I thought the maximum Xmega voltage on any pin was VCC + 0.5 volts and the maximum VCC was 3.6 volts.

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

???

You said you have two diodes, the schematic only shows one diode, where is the other one?

As already mentined, Xmegas run on a MAXIMUM of 3 Volts. Don't run it on 5V !

Please redraw your schematic, and label which boxes are Xmegas, and to which Port.Pin you are connected. Is your USB to serial a chip, or a commercial product? If a chip, are you using a 3V version of the Max232 type chips?

JC

Edit: I believe you mentioned chip to chip communications, so what is the extra USB Input/Output for?

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

So sorry for my late answer. I didn't solve this, didn't work. Thanks for the input though :)