Har en sändar pic som skall sända ut texten "test". När mottagaren får in denna skall den helt enkel sätta en IO hög. Sändaren har den korta koden nedan och funkar. Den sänder verkligen test, har kollat med logikanalysator
Sedan kommer vi till mottagaren. Här har jag tänkt att kolla varje tecken i strängen är rätt. Uppfylls detta så skall OUT gå hög. Men som det ser ut nu så struntar den i if satsen där jag kollar första tecknet. Trots att jag för test lagt in ett a så uppfylls den och utgången går hög. Den verkar inte filtrera alls.
Såg en annan skum sak. Jag har ju ställt 9600 baud men analysatorn säger 1200 baud. Visst både TX o RX är ställda på samma, så med VARANDRA borde ju kommunitkationen funka kan jag tycka.
Du har inte behörighet att öppna de filer som bifogats till detta inlägg.
Nu är jag ju inte så slängd på C, men jag undrar vad, if(uart_rd[0]='a'), gör?
Antar att den kollar om första fältet i arrayen är just 'a'.
Om detta stämmer så undrar jag hur den blir det om man skickar "test"?
Jag har inte kollat vad den gör, men den här raden är klart misstänkt:
UART1_Read_Text(uart_rd, "test",5);
Vad gör den? läser 5 bytes i taget? varför står "test" med i funktionsanropet?
Där skulle jag börjat/bytt till en funktion som läser ett mottaget tecken.
Description Reads characters received via UART until the delimiter sequence is detected. The read sequence is stored in the parameter output; delimiter sequence is stored in the parameter delimiter.
This is a blocking call: the delimiter sequence is expected, otherwise the procedure exits (if the delimiter is not found).
Parameters :
Output: received text
Delimiter: sequence of characters that identifies the end of a received string
Attempts: defines number of received characters in which Delimiter sequence is expected. If Attempts is set to 255, this routine will continuously try to detect the Delimiter sequence.
Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init.
Example Read text until the sequence “OK” is received, and send back what’s been received:
while (1) {
if (UART1_Data_Ready() == 1) { // if data is received
UART1_Read_Text(output, "OK", 10); // reads text until 'OK' is found
UART1_Write_Text(output); // sends back text
}
}
TS har delay() både i sändare och mottagare. Det finns risk att mottagaren inte hinner med utan det bildas en kö med meddelande som börjar växa tills bufferten skrivs sönder. Att ta emot på serieport är mycket svårare än man tror.
"Delay()": Nej
Läsa in sträng: Nej
Läsa tecken för tecken: Ja
Hantering av timeout: Ja
Description Reads characters received via UART until the delimiter sequence is detected. The read sequence is stored in the parameter output; delimiter sequence is stored in the parameter delimiter.
This is a blocking call: the delimiter sequence is expected, otherwise the procedure exits (if the delimiter is not found).
Parameters :
Output: received text
Delimiter: sequence of characters that identifies the end of a received string
Attempts: defines number of received characters in which Delimiter sequence is expected. If Attempts is set to 255, this routine will continuously try to detect the Delimiter sequence.
Requires UART HW module must be initialized and communication established before using this function. See UARTx_Init.
Example Read text until the sequence “OK” is received, and send back what’s been received:
while (1) {
if (UART1_Data_Ready() == 1) { // if data is received
UART1_Read_Text(output, "OK", 10); // reads text until 'OK' is found
UART1_Write_Text(output); // sends back text
}
}