Microcontroller › AVR › How to interface fingerprint module serially with AVR › Hi, this is what I m doing
April 26, 2011 at 9:47 am
#6035
usman
Participant
Hi, this is what I m doing but unsuccessful…
#define USART_BAUDRATE 57600
#define F_CPU 8000000
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16))) – 1)
//this is the packet i want to transmit. I have define the array as:
char GenImg[12] = { 0xEF, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x03, 0x01, 0x00, 0x05 };
//I have called in the main these functions:
usart_init();
_delay_ms(500);
_delay_ms(500);
send_bytes(GenImg,12);
//this function is for “initialization of usart”:
void usart_init()
{
UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1);
// Use 8-bit character sizes
UCSRC &= ~(1 << UMSEL); // In UCSRC, UMSEL = 0 for asynchronous
UCSRC &= ~(1<<USBS); //In UCSRC, USBS = 0 => 1 stop bit
UBRRL = BAUD_PRESCALE;
// Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> ; // Load upper 8-bits of the baud rate value..
// into the high byte of the UBRR register
}
//this is function for transmitting:
void send_bytes(char *s, int length)
{
while (length–)
{
usart_transmit(*s);
s++;
}
}
void usart_transmit(unsigned char c)
{
while(!(UCSRA & (1 << UDRE))); // wait until UDR ready
UDR = c; // send character
}
Please help me to correct any errors!