papuadive
04.11.2013, 17:02
Hallo, möchte gerne drei RF-ID Module (ID-20 Innovations) einlesen und die 12 Ziffern (jeder Tag hat 12 Zeichen) weiterverarbeiten. Das Modul hat eine Datenrate von 9600 Baud und spukt TTL-Daten aus. Ist das mit einem µC überhaupt möchte? Möchte auch noch andere Dinge erledigen. Momentan kann ich nicht einmal ein Zeichen rausbringen. Verwende von Peter Fleury die Lib. Leider bekomme ich nichts auf dem Display angezeigt. Was läuft hier falsch? Danke
/************************************************** ***********************
Title: example program for the Interrupt controlled UART library
Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
File: $Id: test_uart.c,v 1.5 2012/09/14 17:59:08 peter Exp $
Software: AVR-GCC 3.4, AVRlibc 1.4
Hardware: any AVR with built-in UART, tested on AT90S8515 at 4 Mhz
DESCRIPTION:
This example shows how to use the UART library uart.c
************************************************** ***********************/
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "uart.h"
/* define CPU frequency in Mhz here if not defined in Makefile */
#ifndef F_CPU
#define F_CPU 4000000UL
#endif
/* 9600 baud */
#define UART_BAUD_RATE 9600
int main(void)
{
unsigned int c;
char buffer[7];
int num=134;
lcd_init(); // lcd init
vWillkommen(); // Begrüssungstext
_delay_ms(2000); // warte, damit Anzeige nicht gleich weg ist
DDRA = 0xFF; // PORTA Ausgang
PORTA = 0xFF; // Alle auf EIN
/*
* Initialize UART library, pass baudrate and AVR cpu clock
* with the macro
* UART_BAUD_SELECT() (normal speed mode )
* or
* UART_BAUD_SELECT_DOUBLE_SPEED() ( double speed mode)
*/
uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
/*
* now enable interrupt, since UART library is interrupt controlled
*/
sei();
/*
* Transmit string to UART
* The string is buffered by the uart library in a circular buffer
* and one character at a time is transmitted to the UART using interrupts.
* uart_puts() blocks if it can not write the whole string to the circular
* buffer
*/
uart_puts("String stored in SRAM\n");
/*
* Transmit string from program memory to UART
*/
uart_puts_P("String stored in FLASH\n");
/*
* Use standard avr-libc functions to convert numbers into string
* before transmitting via UART
*/
itoa( num, buffer, 10); // convert interger into string (decimal format)
uart_puts(buffer); // and transmit string to UART
/*
* Transmit single character to UART
*/
uart_putc('\r');
for(;;)
{
/*
* Get received character from ringbuffer
* uart_getc() returns in the lower byte the received character and
* in the higher byte (bitmask) the last receive error
* UART_NO_DATA is returned when no data is available.
*
*/
c = uart_getc();
if ( c & UART_NO_DATA )
{
/*
* no data available from UART
*/
// hier etwas mit c machen z.B. auf PORT ausgeben
}
else
{
/*
* new data available from UART
* check for Frame or Overrun error
*/
if ( c & UART_FRAME_ERROR )
{
/* Framing Error detected, i.e no stop bit detected */
uart_puts_P("UART Frame Error: ");
}
if ( c & UART_OVERRUN_ERROR )
{
/*
* Overrun, a character already present in the UART UDR register was
* not read by the interrupt handler before the next character arrived,
* one or more received characters have been dropped
*/
uart_puts_P("UART Overrun Error: ");
}
if ( c & UART_BUFFER_OVERFLOW )
{
/*
* We are not reading the receive buffer fast enough,
* one or more received character have been dropped
*/
uart_puts_P("Buffer overflow error: ");
}
/*
* send received character back
*/
uart_putc( (unsigned char)c );
//++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++
// ab hier mein Teil der Programmierung
//++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++
ID_Werte('a'); //Daten auf LCD ausgeben *-*-*-*-*-*-*-*-*-*-*-*-*-*
/* void ID_Werte(char *wert)
{
lcd_clear();
// itoa(WERT,Value,10); // umwandeln einer dez.-Zahl (WERT zB 11) in ASCII-Zeichen 11 (LCD kann nur ASCII-Zeichen ausgeben!!!)
// itoa(-12,Value,10); // umwandeln der Zahl -12 in ASCII -12 (LCD kann nur ASCII-Zeichen ausgeben!!!)
lcd_pos(2,0);
lcd_text("ID-Wert:");
lcd_pos(3,10);
lcd_text(wert);
}
*/
//+++++++++++++++++++++++++++++ ENDE meiner Programmierung +++++++++++++++++++++++++++++++++
}
}
}
/************************************************** ***********************
Title: example program for the Interrupt controlled UART library
Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
File: $Id: test_uart.c,v 1.5 2012/09/14 17:59:08 peter Exp $
Software: AVR-GCC 3.4, AVRlibc 1.4
Hardware: any AVR with built-in UART, tested on AT90S8515 at 4 Mhz
DESCRIPTION:
This example shows how to use the UART library uart.c
************************************************** ***********************/
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "uart.h"
/* define CPU frequency in Mhz here if not defined in Makefile */
#ifndef F_CPU
#define F_CPU 4000000UL
#endif
/* 9600 baud */
#define UART_BAUD_RATE 9600
int main(void)
{
unsigned int c;
char buffer[7];
int num=134;
lcd_init(); // lcd init
vWillkommen(); // Begrüssungstext
_delay_ms(2000); // warte, damit Anzeige nicht gleich weg ist
DDRA = 0xFF; // PORTA Ausgang
PORTA = 0xFF; // Alle auf EIN
/*
* Initialize UART library, pass baudrate and AVR cpu clock
* with the macro
* UART_BAUD_SELECT() (normal speed mode )
* or
* UART_BAUD_SELECT_DOUBLE_SPEED() ( double speed mode)
*/
uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
/*
* now enable interrupt, since UART library is interrupt controlled
*/
sei();
/*
* Transmit string to UART
* The string is buffered by the uart library in a circular buffer
* and one character at a time is transmitted to the UART using interrupts.
* uart_puts() blocks if it can not write the whole string to the circular
* buffer
*/
uart_puts("String stored in SRAM\n");
/*
* Transmit string from program memory to UART
*/
uart_puts_P("String stored in FLASH\n");
/*
* Use standard avr-libc functions to convert numbers into string
* before transmitting via UART
*/
itoa( num, buffer, 10); // convert interger into string (decimal format)
uart_puts(buffer); // and transmit string to UART
/*
* Transmit single character to UART
*/
uart_putc('\r');
for(;;)
{
/*
* Get received character from ringbuffer
* uart_getc() returns in the lower byte the received character and
* in the higher byte (bitmask) the last receive error
* UART_NO_DATA is returned when no data is available.
*
*/
c = uart_getc();
if ( c & UART_NO_DATA )
{
/*
* no data available from UART
*/
// hier etwas mit c machen z.B. auf PORT ausgeben
}
else
{
/*
* new data available from UART
* check for Frame or Overrun error
*/
if ( c & UART_FRAME_ERROR )
{
/* Framing Error detected, i.e no stop bit detected */
uart_puts_P("UART Frame Error: ");
}
if ( c & UART_OVERRUN_ERROR )
{
/*
* Overrun, a character already present in the UART UDR register was
* not read by the interrupt handler before the next character arrived,
* one or more received characters have been dropped
*/
uart_puts_P("UART Overrun Error: ");
}
if ( c & UART_BUFFER_OVERFLOW )
{
/*
* We are not reading the receive buffer fast enough,
* one or more received character have been dropped
*/
uart_puts_P("Buffer overflow error: ");
}
/*
* send received character back
*/
uart_putc( (unsigned char)c );
//++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++
// ab hier mein Teil der Programmierung
//++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++
ID_Werte('a'); //Daten auf LCD ausgeben *-*-*-*-*-*-*-*-*-*-*-*-*-*
/* void ID_Werte(char *wert)
{
lcd_clear();
// itoa(WERT,Value,10); // umwandeln einer dez.-Zahl (WERT zB 11) in ASCII-Zeichen 11 (LCD kann nur ASCII-Zeichen ausgeben!!!)
// itoa(-12,Value,10); // umwandeln der Zahl -12 in ASCII -12 (LCD kann nur ASCII-Zeichen ausgeben!!!)
lcd_pos(2,0);
lcd_text("ID-Wert:");
lcd_pos(3,10);
lcd_text(wert);
}
*/
//+++++++++++++++++++++++++++++ ENDE meiner Programmierung +++++++++++++++++++++++++++++++++
}
}
}