Mahlzeit!
3 Schüsse ins Blaue:
1. Timing Problem?
2. Konvertierungsproblem?Code:void SendDataPackage(uint8_t Identifier, uint16_t value) { // --- value zerlegen uint8_t highB = (uint8_t)(value >> 8); uint8_t lowB = (uint8_t)value; // --- senden USART1_Transmit(_StartCond); //Das hier kommt richtig an USART1_Transmit(Identifier); //Das hier kommt richtig an USART1_Transmit(lowB); //Das hier kommt FALSCH an USART1_Transmit(highB); //Das hier kommt richtig an USART1_Transmit(_EndCond); //Das hier kommt richtig an }
3. Übertragung mit enm bekannten Testbyte (Timing die 2.)?Code:void SendDataPackage(uint8_t Identifier, uint16_t value) { // --- value zerlegen uint8_t lowB = (uint8_t) (value & 0xff); uint8_t highB = (uint8_t) (value >> 8); // --- senden USART1_Transmit(_StartCond); //Das hier kommt richtig an USART1_Transmit(Identifier); //Das hier kommt richtig an USART1_Transmit(lowB); //Das hier kommt FALSCH an USART1_Transmit(highB); //Das hier kommt richtig an USART1_Transmit(_EndCond); //Das hier kommt richtig an }
Ich bau mir fürs Senden per UART immer einen Puffer:Code:void SendDataPackage(uint8_t Identifier, uint16_t value) { // --- value zerlegen uint8_t lowB = (uint8_t) (value & 0xff); uint8_t highB = (uint8_t) (value >> 8); // --- senden USART1_Transmit(_StartCond); //Das hier kommt richtig an USART1_Transmit(Identifier); //Das hier kommt richtig an USART1_Transmit(0xaa); //Das hier kommt FALSCH an USART1_Transmit(highB); //Das hier kommt richtig an USART1_Transmit(_EndCond); //Das hier kommt richtig an }
Da die USART einen Int wirft wenn der TX Puffer der USART leer ist, kann man dann den Puffer schön in einer int routine rausschreiben und derweil was anderes sinnvolles tunCode:uint8_t txbuffer[5]; void SendDataPackage(uint8_t Identifier, uint16_t value) { // --- value zerlegen txbuffer[2] = (uint8_t) (value & 0xff); txbuffer[3] = (uint8_t) (value >> 8); // --- frame bauen txbuffer[0] = _StartCond; txbuffer[1] = Identifier; txbuffer[4] = _EndCond; // --- senden send_txbuffer(5); } void send_txbuffer(uint8_t len) { for (uint8_t i=0;i<len;i++) { USART1_Transmit(txbuffer[i]); } }Und im PC kommt alles schön auf einmal an, da die Bytes am Stück geschrieben werden.
Viel Glück![]()







Zitieren

Lesezeichen