main.c File Reference


Detailed Description

This is an example for testing the One-wire Software UART.

Data will be received and sent back when a return character is received or the data array is full.

Application note:
AVR274: Single-wire Software UART
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
Name
Revision
1222
RCSfile
main.c,v
Date
2006-11-14 17:32:38 +0100 (ti, 14 nov 2006)

Definition in file main.c.

#include "single_wire_UART.h"
#include <ioavr.h>
#include <inavr.h>

Include dependency graph for main.c:

Go to the source code of this file.

Defines

#define RECEIVED_DATA_SIZE   8

Functions

int main (void)
 Main loop.
void Print_String (char *str)
 Sends an array of data.


Define Documentation

#define RECEIVED_DATA_SIZE   8

Definition at line 31 of file main.c.

Referenced by main().


Function Documentation

int main ( void   ) 

Main loop.

This contains a while loop receiving data until the received_data array is full or a return character is received. It will then send back the received data and repeat the loop.

< Enable global interrupts.

< Stop receiving if buffer is full or a return character is received.

< Send back received data.

Definition at line 65 of file main.c.

References Print_String(), READ_FLAG, RECEIVED_DATA_SIZE, SW_UART_Enable(), SW_UART_FRAME_ERROR, SW_UART_Receive(), SW_UART_RX_BUFFER_FULL, SW_UART_RX_BUFFER_OVERFLOW, and SW_UART_status.

00066 {
00067   __enable_interrupt();   
00068   SW_UART_Enable();
00069   DDRB = 0xFF;
00070   PORTB = 0xFF;
00071   uint8_t received_data[RECEIVED_DATA_SIZE];
00072   uint8_t i;
00073   for(i=0;i<RECEIVED_DATA_SIZE;i++)
00074   {
00075     received_data[i] = 0; 
00076   }
00077   i=0;
00078 
00079   //Print_String("Test Program\n\r");
00080   for(;;)
00081   {
00082     if( READ_FLAG(SW_UART_status, SW_UART_RX_BUFFER_OVERFLOW))      
00083     {
00084       PORTB = 0x0F;
00085       for(;;){}
00086     }
00087     if( READ_FLAG(SW_UART_status, SW_UART_FRAME_ERROR) )
00088     {
00089       PORTB = 0xF0;
00090       for(;;){}
00091     }
00092     while( (!READ_FLAG(SW_UART_status, SW_UART_RX_BUFFER_FULL)) ){} 
00093       
00094     received_data[i] = SW_UART_Receive();
00095     i++;
00096     if( (i >= RECEIVED_DATA_SIZE-1) || (received_data[i-1] == 0x0D) ) 
00097     {
00098       received_data[i] = '\0';
00099       Print_String(((char *) received_data));    
00100       i = 0;
00101     } 
00102   }
00103 }

Here is the call graph for this function:

void Print_String ( char *  str  ) 

Sends an array of data.

This function sends an array of data to the UART. If TX buffer is full, the function will busy wait until there is room in the buffer. The array must end with a string terminator ('
').

Definition at line 42 of file main.c.

References READ_FLAG, SW_UART_FRAME_ERROR, SW_UART_status, SW_UART_Transmit(), and SW_UART_TX_BUFFER_FULL.

Referenced by main().

00043 {
00044   while( *str != '\0' )
00045   {
00046     if( !READ_FLAG(SW_UART_status, SW_UART_TX_BUFFER_FULL) )
00047     {
00048       SW_UART_Transmit((uint8_t) *str++);
00049     }
00050     if( READ_FLAG(SW_UART_status, SW_UART_FRAME_ERROR) )
00051     {
00052       PORTB = 0xF0;
00053       for(;;){}
00054     }
00055   }
00056 }

Here is the call graph for this function:


Generated on Mon Apr 23 10:13:58 2007 for AVR274: Single-wire Software UART by  doxygen 1.5.1-p1