UC3 string through an XBEE module

Go To Last Post
9 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.

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

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

hani I have deleted your other posts as you requested, please keep everything here from now on regarding this topic.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I have used dozens of XBEE modules and i never have heard about or have seen Sample Data. XBEE modules out of the box are simple serial to rf modules. You can take two of them out of the box and have comms between two PCs or microcontrollers at 9600 baud in minutes.

Can you post a schematic of how all of this is connected?

Are you sure you are communicating at 9600?

Just thought of something....if you sent three "###" to the module it will switch to command mode. What are you sending to the XBEE?

Which model XBEE? There is the standard unit and the one that has a micro on it.

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

Thanks all for the help, I changed the router from API mode to AT, also redefined the packetization timout RO as 0 and it worked fine !

 

I also re-wrote the code as follows 

#include <asf.h>
#include <user_board.h>

void xbee_putstring(char *str);

int main (void)
{
	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();

	// Assign GPIO to USART.
	gpio_enable_module(USART_GPIO_MAP,sizeof(USART_GPIO_MAP) / sizeof(USART_GPIO_MAP[0]));

	// Initialize USART in RS232 mode.
	usart_init_rs232(&XBEE_USART, &USART_OPTIONS, sysclk_get_main_hz());

	xbee_putstring("HelloWorld");

}

void xbee_putstring(char *str)
{
	while (*str)
	{
		usart_putchar(&XBEE_USART, *str++);
	}
}

 

Last Edited: Wed. Jul 5, 2017 - 08:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js wrote:

hani I have deleted your other posts as you requested, please keep everything here from now on regarding this topic.

Will do, thanks !

Last Edited: Wed. Jul 5, 2017 - 08:42 PM