Microcontroller › AVR › “Hello World!” with ATxmega256A3
- This topic has 0 replies, 1 voice, and was last updated 8 years, 11 months ago by Gabriella.
-
AuthorPosts
-
October 8, 2015 at 12:30 pm #4039GabriellaParticipant
Hi all,
I am using two radio extender boards from a REB233SMAD-EK kit and an AVRISP mkII programmer in Atmel Studio 6.2. Though the two boards seem to be recognizing each other (LED diodes blink to show successful wireless communication), I cannot find a way in which to get them to send/receive a simple message (such as "Hello World!"). I've been told that the AVRISP mkII is simply a programmer, meaning it doesn't debug. Because of this, whenever I try to debug the following code, Atmel Studio consistently displays an error message stating "Failed to launch program. Error: Failed to start programming session before chip erase with eeprom preserve:Failed to enter programming mode. Error status received from tool: Result received is 0x03.":/*
* Hello_World.c
*
* Created: 8/21/2015 2:23:17 PM
* Author: Hugo
*/
#include <stdio.h>
#include <avr/io.h>
static int uart_putchar(char c, FILE *stream);
static void uart_init (void);
static FILE mystdout = FDEV_SETUP_STREAM (uart_putchar, NULL, _FDEV_SETUP_WRITE);
int main (void)
{
uart_init();
stdout = &mystdout;
while (1)
printf("Hello, world!n");
}
static int uart_putchar (char c, FILE *stream)
{
if (c == 'n')
uart_putchar('r', stream);
// Wait for the transmit buffer to be empty
while ( !( USARTC0.STATUS & USART_DREIF_bm) );
// Put our character into the transmit buffer
USARTC0.DATA = c;
return 0;
}
// Init USART. Transmit only (we're not receiving anything)
// We use USARTC0, transmit pin on PC3.
// Want 9600 baud. Have a 2 MHz clock. BSCALE = 0
// BSEL = ( 2000000 / (2^0 * 16*9600)) -1 = 12
// Fbaud = 2000000 / (2^0 * 16 * (12+1)) = 9615 bits/sec
static void uart_init (void)
{
// Set the TxD pin high – set PORTC DIR register bit 3 to 1
PORTC.OUTSET = PIN3_bm;
// Set the TxD pin as an output – set PORTC OUT register bit 3 to 1
PORTC.DIRSET = PIN3_bm;
// Set baud rate & frame format
USARTC0.BAUDCTRLB = 0; // BSCALE = 0 as well
USARTC0.BAUDCTRLA = 12;
// Set mode of operation
USARTC0.CTRLA = 0; // no interrupts please
USARTC0.CTRLC = 0x03; // async, no parity, 8 bit data, 1 stop bit
// Enable transmitter only
USARTC0.CTRLB = USART_TXEN_bm;
}I am unsure of how to get the "Hello World!" message communicated between my two boards using the AVRISP mkII. Would I need a debugger? Is there a way I can program without it?
Any help would be very appreciated!!
-
AuthorPosts
- You must be logged in to reply to this topic.