UART MC<--->HANDY Quellcode Problem?

Gast #790027
Lesenswert?
• ▲
▼
hallo,


ich habe ein Quellcode zusammengebastelt und wollte mal fragen, ob da 
eventuell ein Fehler drin steckt, da die serielle Verbindung zwischen 
Handy und uC nicht funktioniert. Die Verbindung zwischen PC und uC oder 
PC und Handy funktioniert. Hab ein Atmega8 und benutze ein 
Spannungsteiler als Pegelwandler...

//included Header & defines
//----------------------------------------------------------------------
#include  <avr\io.h>
#include  <util/delay.h>
#include  <stdint.h>
#include  <inttypes.h>
#include  <stdio.h>
#include  <ctype.h>
#include  <stdlib.h>
#define   F_CPU 3686400L
#define   BAUD 9600L
#define   UBRR_BAUD ((F_CPU/(16L*BAUD))-1)
#define   CR "\r\n"
//----------------------------------------------------------------------
//Prototyping
void uart_init(void);
void uart_puts (const char *s);
static inline int uart_putc (const uint8_t c);
static inline uint8_t uart_getc_wait();
static inline int uart_getc_nowait();
//----------------------------------------------------------------------
//MAIN
int main(void)
{
  uint8_t buffer;
  uart_init();
  while (1)
  {
    if ((uart_getc_wait())=='1')
    {
      uart_puts ("ATD017621163186" CR);
    }
  else;

  }
  return 0;
}
//----------------------------------------------------------------------
Functions
void uart_init(void)
{
  // Baudrate einstellen
  UBRRH = (uint8_t) (UBRR_BAUD>>8);
  UBRRL = (uint8_t) (UBRR_BAUD & 0x0ff);

  // Aktivieren von receiver und transmitter
  UCSRB = (1<<RXEN)|(1<<TXEN);

  // Datenformats: 8 Datenbits, 1 Stoppbit
  UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
  //flushen
  do
  {
    UDR;
  }
  while (UCSRA & (1 << RXC));
}

void uart_puts (const char *s)       // String übertragen.
{
  do
  {
    uart_putc (*s);
  }
  while (*s++);
}

static inline int   uart_putc (const uint8_t c)
{
  while (!(UCSRA & (1 << UDRE)));
  UDR = c;
  return 1;
}

static inline uint8_t uart_getc_wait()
{
  while (!(UCSRA & (1 << RXC)));
  return UDR;
}

static inline int  uart_getc_nowait()
{
  return (UCSRA & (1 << RXC)) ? (int) UDR : -1;
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren