rahulkalpsts107
Newbie level 4
- Joined
- May 21, 2013
- Messages
- 7
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,336
Hi All,
I have an issue with UART which i have been struggling for a long time .
None of my uart messages are displayed . I have interfaced a serial lcd that accepts incoming uart at 9600bps
This is my code :
My Fuse settings currently are HIGH : 0x99 LOW : 0xEE
The Serial LCD just takes vcc,gnd,and rxd . My TXD is connected to its RXD and my circuit is at +5v , even serial lcd is configured to work at that level.
This is configured for external 4Mhz clock during build time .
Please help me with this . I really dont know what the issue is.
Thankyou
Regards,
Rahul
I have an issue with UART which i have been struggling for a long time .
None of my uart messages are displayed . I have interfaced a serial lcd that accepts incoming uart at 9600bps
This is my code :
Code:
/*----------------------------------------------------------------
-----------------HEADER FILES-------------------------------------
-----------------------------------------------------------------*/
#include<avr/io.h> //HEADER FILE FOR AVR INPUT OUTPUT
#include<compat/deprecated.h> //HEADER FILE FOR FUNCTIONS LIKE SBI AND CBI
#include<util/delay.h> //HEADER FILE FOR DELAY
/*----------------------------------------------------------------
-----------------MAIN PROGRAM-------------------------------------
-----------------------------------------------------------------*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#ifndef UART_H
#define UART_H
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
//No need to call this function directly, it's just here for printf().
//Outputs a single character to the UART when the transmit buffer is empty.
//This is the function that we bind to printf so it can output the string
//that printf generates. The FILE parameter is required by printf for behind-
//the-scenes bookkeeping. *Note that we can write a function that will put a
//single char anywhere we want -- parallel interface, SPI, I2C, etc.*
//Set up the registers that control the UART and bind put_uart_char
//as our output function.
#endif
int put_uart_char(char c, FILE *fd)
{
while (!(UCSRA & _BV(UDRE))); //Wait for transmit buffer to become empty.
UDR = c; //Write the character to the UART.
return 0;
}
void uart_init(int baud)
{
/* Set baud rate */
UBRRH = (unsigned char )(baud>>8);
UBRRL = (unsigned char )baud;
/* Enable receiver and transmitter */
UCSRB = (1<<RXEN)|(1<<TXEN);
/* Set frame format: 8data, 1stop bit */
UCSRC = (1<<URSEL)|(3<<UCSZ0);
}
void USART_Transmit( unsigned char data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRA & (1<<UDRE)) )
;
/* Put data into buffer, sends the data */
UDR = data;
//Call fdevopen. This is what binds printf to put_uart_char. The first
//parameter is the address of our function that will output a single
//character, the second parameter is an optional parameter that is
//used for get functions, ie. receiving a character from the UART.
//This is the function that uses malloc.
fdevopen(&put_uart_char, NULL);
//Enable the interrupts globally.
SREG |= _BV(SREG_I);
}
int main(void)
{
int i,temp;
DDRB=0XFF; //SET DATA DIRECTION REGISTER
//SET 1 for OUTPUT PORT
//SET 0 FOR INPUT PORT
//ALL OTHERS ARE OUTPUT
DDRD=0XF0; //SET DATA DIRECTION REGISTER
//SET 1 for OUTPUT PORT
//SET 0 FOR INPUT PORT
//PD.1, PD.2 AND PD.3 ARE INPUT
//ALL OTHERS ARE OUTPUT
sbi(PORTD,0); //ENABLE PULL UP FOR SW1
sbi(PORTD,1); //ENABLE PULL UP FOR SW2
sbi(PORTD,2); //ENABLE PULL UP FOR SWITCH INT0
sbi(PORTD,3); //ENABLE PULL UP FOR SWITCH INT1
int k = 200;
uart_init(25);
_delay_ms(400);
while(1)
{
PORTB = 0x0;
_delay_ms(400);
PORTB = 0xFF;
k--;
put_uart_char(0xCA , NULL);
}
while(1);
return(0);
}
My Fuse settings currently are HIGH : 0x99 LOW : 0xEE
The Serial LCD just takes vcc,gnd,and rxd . My TXD is connected to its RXD and my circuit is at +5v , even serial lcd is configured to work at that level.
This is configured for external 4Mhz clock during build time .
Please help me with this . I really dont know what the issue is.
Thankyou
Regards,
Rahul