CE351 lec21 IR transmitting and receiving a message
Overview
Yiyan Li explains how an IR message is framed, transmitted, and received using UART, with an additive checksum and a null byte to mark the message end. The message contains placeholder source and destination bytes, typed characters, a null terminator, and a checksum; a receive interrupt copies each incoming byte from UART1's UDR1 register into a memory buffer because UART provides no acknowledgment or flow control.
Key takeaways
- The message format uses two placeholder address bytes, user text, a null terminator, and a checksum; all bytes before the checksum contribute to the checksum.
- A null byte provides a reliable message boundary when the receiver does not know the typed message length in advance, and the checksum immediately follows it.
- The additive ASCII checksum detects many transmission errors but can miss errors when altered characters yield the same sum.
- UART receive interrupts capture bytes independently of the main program, but the ISR must copy each byte from UDR1 quickly because this setup has no acknowledgment or flow control.
- Enter completes message construction, S initiates transmission, and R only prints bytes already received by the ISR.
- A UART frame carrying 8 data bits uses 10 transmitted bits when one start bit and one stop bit are included.
Chapters
- For a message such as ABCD, the checksum is the sum of the characters' ASCII codes, sent as an additional byte.
- The receiver recomputes the sum and compares it with the received checksum; a mismatch indicates likely transmission corruption.
- An additive checksum is not foolproof: different corrupted characters can produce the same total, though Li describes accidental matches as unlikely.
- The message layout is source address, destination address, user-entered characters, a null byte, and a checksum.
- The two address bytes are predefined placeholders in this exercise, but they are included in the checksum along with the message characters.
- Pressing M initializes the address bytes and checksum; the character index starts at 2 because those bytes occupy the first two buffer positions.
- Typed characters are echoed to the serial monitor and added to the message buffer and checksum until Enter is pressed or the buffer limit is reached.
- A null byte marks the end of user-entered content whose length is not known in advance; the following byte is the checksum.
- The program reserves the final two buffer positions for the null byte and checksum, stopping character entry before those positions.
- UART reception triggers an interrupt for each byte, so the receiver must promptly copy each byte into a software buffer before the next arrives.
- UART transmission has no acknowledgment or flow-control mechanism in this setup, so the receiver must keep up with the incoming byte rate.
- Pressing Enter finishes message construction by appending the null byte and checksum; it does not start transmission.
- Pressing S starts transmission of the complete multi-byte message, with a transmission ISR handling the process in the background.
- Pressing R displays data already collected by the receive interrupt; it does not trigger reception.
- The class review notes that a UART byte with 8 data bits uses 10 transmitted bits when the start and stop bits are included.
- The receive ISR runs when a byte arrives, and the received data is available in the UART1 data register, UDR1.
- The ISR stores each byte with an indexed operation such as buffer[index++] = UDR1, advancing the index for the next interrupt.
- The ISR checks incoming data for the null terminator while continuing to store bytes; after the null byte, the next byte is the checksum.
- Li recommends reading the low-level UDR1 register directly in a manually written ISR rather than relying on a higher-level serial-read function.
Transcript excerpt
0:00 and one each time. So the better strategy to do that is having a receiver interrupt. So what's happening is um the receiver is being controlled. Um so whenever one bite is being received it, uh it stored it into something else. You can do it like receiver um or re say receive the message. You have an index over there, right? So every time the interrupt happens, you store whatever in the buffer into this guy and then you do I plus+ okay you probably plus one plus one to it or you can do this. So add a one to I or index. Uh so in that case the next time it interrupts uh there will be a new bite uh in the
0:51 buffer for sure because it only interrupts whenever a bite is received. So everything can be controlled. You're not hopefully you're are not missing anything. Um but there are still cases that you probably will lose a message due to a lot of reasons. For example, the IR is not transmitting reliably for some reason. Um so so in that case uh what we can do is we when you send uh for example multiple characters multiple characters I'm sending a b c d here right. So before I send it, I construct another bite here as a trike bite. Okay. So that number here will be the addition of all the ASI code for example.
1:39 Okay. And and that number will be another another bite to be sent. So you can use that bite as a error checking message. For example, A B CD. We just do a A plus B plus C plus D because characters are being added together. They're actually adding their S code together. You get a summation of A plus B plus C plus D. It's a pretty
This is the start of the transcript. Save this video free for the whole transcript, searchable and time-coded.
In this course
Related notes
Summary, takeaways, and chapters were generated by AI from the video's transcript and may contain errors. The video belongs to its creator, Yiyan Li.