UC3 string through an XBEE module

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

hello all, I'm trying to send and receive a string through an XBEE module, but all I am getting is the XBEE sample data which means that the string is not being transferred. My code is as follows, (please bear in mind that I am new to mechatronics), any ideas ? I am using the AT32UC3C2512 which is why i can't use the data direction registers commands (DDRB, UDR0, ... )

 

 

#include <asf.h>

int main (void)
{
    
    uint8_t tx_buf[] = "\n\rHHHH";
    uint8_t tx_length = 6;
    uint8_t received_byte;
    uint8_t i;
    
    const gpio_map_t USART_GPIO_MAP =
    {
        #if defined(AVR32_USART3)
        {83, 5},
        
        {84, 5},
        
        {82, 5},
        
        {117, 0},
        #endif
    };
    
    const usart_options_t USART_OPTIONS =
    {
        .baudrate = 9600,
        .channelmode = USART_NORMAL_CHMODE,
        .charlength = 8,
        .paritytype = USART_NO_PARITY,
        .stopbits = USART_1_STOPBIT,
    };
    
    board_init();
    sysclk_init();
    
   
    gpio_enable_module(USART_GPIO_MAP,
    sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

  
    usart_init_rs232(&XBEE_USART, &USART_OPTIONS, sysclk_get_main_hz());

    
    for (i=0; i<tx_length; i++)
    {

        usart_putchar(&XBEE_USART, tx_buf[i]);

        
    }

   
    while (true)
     {
        received_byte = usart_getchar(&XBEE_USART);
        if (received_byte == '\r') {
            for (i = 0; i < tx_length; i++) {
                usart_putchar(&XBEE_USART, tx_buf[i]);
            }
        } else
        usart_putchar(&XBEE_USART, received_byte);
      }
}

 

Thanks.

HN

Last Edited: Mon. Jun 19, 2017 - 10:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is an AT32UC3C2512 ?

 

Did you try to send a string to your PC (via an USB serial adapter)? -1rst thing to be done, for any UC : usb_serila adapters and PC terminals are work , if you do not see on the terminal what you want to send, there is already an issue....

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

Split and moved to UC3 forum.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

hani_N wrote:
please bear in mind that I am new to mechatronics)

Actually, that's something that you need to bear in mind.

 

When you are new to something, you need to begin with the basics, and work up from there - rather than jump straight in over your head!

 

As dbrion0606 says, you really need to be sure that you have basic wired serial comms fully understood and working before adding the complexity of radios ...

 

See the "Getting Started" tips & resources here: http://www.avrfreaks.net/comment...

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

What is "... the XBEE sample data ..." ?
Where does that sample data appear ?, (at the other end, or in your variable received_byte ?)


I assume that XBEE_USART is #defined to be AVR32_USART3


It is a 'good idea' to check that usart_init_rs232(,,) returns USART_SUCCESS