Hallo Zusammen,
ich will derzeit die Verbindung zu einem CMPS10 Board von seriell 9600 Baud auf 19200, lieber aber auf 38400 Baud setzen.
Die Kommunikation klappt mit 9600 Baud ohne Probleme, ist mir aber zu langsam.
Leider arbeitet die Kommunikation nur mit 9600 und die Routinen scheinen in den Warteschleifen sich zu verewigen.
Ich verwende die Routinen aus dem Mirokontroller Forum hierfür: http://www.mikrocontroller.net/artic...orial/Der_UART
Das mache ich mit folgenden Routinen im Startup:
Teile der Startup routine:
Code:RS232_Init(BAUD_RATE9600); // Init Port for the stand of the Compass RS232_PutByte(0xA1); // Setup the Compass for 38400Baud RS232_Init(BAUD_RATE38400); // Init Port now to 38400Baud as well Delay_ms(500); // Wait unit external hardware is ready iRs232State=RS232_GetByte(&(m_RS232_Buffer[0])); // get the Baudrate Ok InitSPIInterface(); sei(); // release the interrupts
Hier die Definition der Baurate
Hier die Init Routine und die RS232 Put routineCode:/** Baud rates for the serial communication */ #define BAUD_RATE9600 9600UL // Ul definition, otherwise problems #define BAUD_RATE19200 19200UL #define BAUD_RATE38400 38400UL #define UBRR_VAL ((SYSCLOCK+BAUD_RATE38400*8)/(BAUD_RATE38400*16)-1) //clever runde #define BAUD_REAL (SYSCLOCK/(16*(UBRR_VAL+1))) //reale Baudrate #define BAUD_ERROR ((BAUD_REAL*1000)/BAUD_RATE38400) //Fehler in Promille #if ((BAUD_ERROR<990)||(BAUD_ERROR>1010)) #error Systematischer Fehler in der Baudrate größer 1% und damit zu hoch! #endif
Init RS232
Die Verkabelung ist nicht länger als 8 cm und auf reiner TTL Ebene.Code:/******************************************************* Function: RS232_Init Purpose: Initialise the RS232 serial link Input Parameter: Baurate for the UART to use Return Value: None *******************************************************/ void RS232_Init(uint32_t iBaurate) { /* ** Enable TXEN and RXEN in register UCSRB */ UCSRB |= (1 << TXEN); UCSRB |= (1 << RXEN); /* ** Set transmission type, Asynchron 8Bit None Parity 2 Stop bit */ UCSRC = (1 << URSEL)|(1<< USBS)| (1<<UCSZ0) | (1<<UCSZ1); /* ** Set baud rate */ UBRRH = ((SYSCLOCK / (iBaurate * 16L) - 1)>>8); UBRRL = (SYSCLOCK / (iBaurate * 16L) - 1); do { UDR; } while (UCSRA & (1 << RXC)); } /******************************************************* Function: RS232_PutByte Purpose: Send to the UART a data byte Input Parameter: the byte Return Value: None Value = 0 *******************************************************/ void RS232_PutByte (uint8_t Byte) { /* ** Wait until previous character is sent */ while (!(UCSRA & (1<<UDRE))); /* ** Send byte to UART */ UDR = Byte; return; }
Hat jemand eine Idee, wo ich noch weiter suchen kann.
Mein Program bleibt komplett in den RS232 Routinen stecken.
Meine Vermutung, der CMPS ist weiterhin auf 9600 Baud, da ich nach neuladen
des Controllers und aktivieren von 9600Baud wieder mit dem Board reden kann,
obwohl ich keine 9600 Init Sequenze an den Kompass sende.
Viele Grüße
R.







Zitieren

Lesezeichen