avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Help Needed (UART / USART)


From: mickhail mcanuff
Subject: [avr-gcc-list] Help Needed (UART / USART)
Date: Sun, 18 Mar 2007 15:29:57 -0400

I want to use the At902313 to Transmit the following characters listed in the main() function. The code below was used. I am also using the Atmega8515 to receive this transmitted code (i.e. '8','7','6').
 
#include <stdint.h>
#define F_CPU 3686400UL
#include <avr/io.h>
#include <avr/sfr_defs.h>
 
//////CODE FOR SENDING NUMBER TO THE UDR FOR TX////////
char send_val_1(char a)
{
 UBRR = 95;   //UBRR 2400 baud
 UCR = 0b00001000; //UCR
   
 if (bit_is_set(USR,UDRE));
 
 UDR = a;

return 0;
}

void main (void)
{
 {
 send_val_1('8');
// send_val_1('7');
// send_val_1('6');
 }
return 0;
}
///// END OF TX CODE/////////
 
//Receiving code
 

#include <stdint.h>
#define F_CPU 3686400UL
#include <avr/io.h>

   // Define baud rate

#define UART_BAUD 2400ul
#define UART_UBBR_VALUE ((F_CPU/(UART_BAUD<<4))-1)


void UART_vInit(void)

{

// Set baud rate

UBRRH = (uint8_t)(USART_UBBR_VALUE>>8);

UBRR = (uint8_t)UART_UBBR_VALUE;


// Set frame format to 8 data bits, no parity, 1 stop bit

//UCR = (0<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);


// Enable receiver

UCR = (1<<RXEN);

}


uint8_t UART_vReceiveByte()

{

// Wait until a byte has been received

 while((UCR&(1<<RXC)) == 0);


// Return received data

return UDR;

}


int main(void)

{

uint8_t u8Data;


// Initialise USART

UART_vInit();

// Repeat indefinitely

while (1)

{

//received characters

u8Data = UART_vReceiveByte();

switch(u8Data)
{
 case '0' = PORTB = 0x00;
  break;
 case '1' = PORTB = 0x01;
  break;
 //........ continues to '9'

 case '9' = PORTB = 0xA1;
  break;
}

}

}

The purpose of this code is to receive the data sent from the 2313 and turn on 7 segment display located on PORTB. The code doesnt seem to be receiving. I wonder if the ATmega8515 can communicate with the AT90s2313?? Help pleeeeeze!!!!!!!!!!!! 

 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]