NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Support Forum » RFID reader on UART

January 16, 2011
by gadams
gadams's Avatar

I have a parallax RFID reader and Im trying to read the RFID card IDs to the LCD. The RFID reader supports 2400 baud and 8N1 frame. For 2400 baud I need to reset the UBBRnL & UBBRnH to 383. I've tried changing the uart.c file and compiling it and even changing the values in my main program after the uart_init and I'm getting strange ascii characters. The RFID sends 10 acii characters as the Card ID. I guess it is possible that this is the ID I just think its strange. I seem to get the same result (ID) no matter what I set UBBRnL & UBBRnH to. Any Ideas?

int main() {

  lcd_init();
  FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_WRITE);
  lcd_home();

  // Start up the serial port
  uart_init();
  FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
  stdin = stdout = &uart_stream;

  UBRR0H = 256;
  UBRR0L = 127; // for 2400bps with 14.7456MHz clock
  // enable uart RX and TX
  UCSR0B = (1<<RXEN0)|(1<<TXEN0);
  // set 8N1 frame format
  UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);

  char tc0;
  char tc1;
  char tc2;
  char tc3;
  char tc4;
  char tc5;
  char tc6;
  char tc7;
  char tc8;
  char tc9;
  char tc10;
  char tc11;

  // busy loop
  while(1) 
  {

  tc0 = uart_read();
  tc1 = uart_read();
  tc2 = uart_read();
  tc3 = uart_read();
  tc4 = uart_read();
  tc5 = uart_read();
  tc6 = uart_read();
  tc7 = uart_read();
  tc8 = uart_read();
  tc9 = uart_read();
  tc10 = uart_read();
  tc11 = uart_read();

   lcd_home();
   lcd_line_one();
   lcd_write_data(tc1);
   lcd_write_data(tc2);
   lcd_write_data(tc3);
   lcd_write_data(tc4);
   lcd_write_data(tc5);
   lcd_write_data(tc6);
   lcd_write_data(tc7);
   lcd_write_data(tc8);
   lcd_write_data(tc9);
   lcd_write_data(tc10);
January 16, 2011
by bretm
bretm's Avatar

For 383, UBRR0H would be 1. You have UBRR0L correct. The "H" half is only 8 bits, so setting it to 256 is the same as setting it to 0, so with 0 and 127 you're doing 7200 bps. By setting it to 1 it will contribute 256 to the total because it's 256 * UBRR0H + UBRR0L.

January 16, 2011
by gadams
gadams's Avatar

Thank you. I actually figured that out but it still wouldn't work. After driving myself nuts I finally realized that I hadn't defined the clock speed @ the beginning of my code. (#define F_CPU 14745600). It's now working so I can retrieve the RFID cards ID numbers. I don't know why but when you buy the reader with cards it doesn't tell you the cards ID numbers and you can't do any programming without them. The reader does nothing but read the ID number when the enable pin is pulled low and transmit the ID through serial. You have to use the mcu to pull the pin low and do the ID numbers comparisons. From here I can do all kinds of fun stuff!

Post a Reply

Please log in to post a reply.

Did you know that a piezoelectric buzzer can be used to play music with your microcontroller? Learn more...