Hi I am trying to talk to send a character to the PC using the xmega128a1 and the MAX3232 USART to Serial converter chip. Here is my setup and "send char" function below:

void USARTSetup(){
PORTC.DIRCLR = PIN2_bm;     //Set RxD pin as input
PORTC.DIRSET = PIN3_bm;     //Set TxD pin as output
PORTC.OUTSET = PIN3_bm;     //Set TxD pin high
//The following setup is for a clock of 32MHz
//and a desired baud rate of 19200
USARTD0_BAUDCTRLB = 0xB0;   //set B(scale) to -5
USARTD0_BAUDCTRLA = 0xE5;   //set BSEL to 3301
USARTD0_BAUDCTRLB |= 0x0C;  //set BSEL to 3301
USARTD0_CTRLA = 0x00;       //disable USART interrupts
USARTD0_CTRLB = 0x18;       //enable receive and transmit
USARTD0_CTRLC = 0x03;       //8 data bits, no parity and 1 stop bit

void USARTSendByte(UINT8 data){
while(!(USARTD0_STATUS & USART_DREIF_bm));  //wait until DATA buffer is empty
USARTD0_DATA = data;                        //load data
while(!(USARTD0_STATUS & USART_TXCIF_bm));  //wait until transfer complete
USARTD0_STATUS |= USART_TXCIF_bm;           //write 1 to clear bit

Debugging seems to hang as soon as it reaches this part of the code:


And nothing is sent to hyperterminal.

my wiring is as shown below: Serial Wiring

As you can see, ive looped the handshaking pins and the CTS/RTS pins.

Can anyone help point me in the right direction? I have no idea why i cannot send a byte to the hyperterminal.


For anyone who was wondering what the problem was, I was using the incorrect USART for PORT C

See, the pins are labelled as 'RXD0' and 'TXD0' in the datasheet, (unrelated to the USART number - I dont know what the D0/DO refer to in this instance), however for port C pin2&3, the correct USART is USARTC0.

Changing every instance of USARTD0 to USARTC0 in the above code will make this operational.

Anyone wishing to use rs232 to communicate to an atxmegaA1 may use the above setup.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.