EENG 383

Lab 6 - IR decoder

Lab: 6
Status Live

InLab 6

Some self guided activities.

Lab 6 assignment

Thanks for Alex for putting together this flowchart of the software organiaztion required for this lab. This PDF also contains a few hints in addition to the flowchart.

Software

There are two main components to this week's lab. First, modify the transmit function of the inLab code to transmit a NULL terminated string of character. Second, convert the EUSART2 receive function to operate off an interrupt and store a string of characters in a global array of characters.

EUSART2
Start by modifying the EUSART2 configuration in MCC and checking "Enable EUSART Interrupts". Do not redirect EUSART2 to STDIO because that is EUSART1's job (because EUSART1 is connected to the FT230 chip which creates the virtual COM port on your PC). Make sure to regenerate the MCC files. Back in main, make sure to include the following code after your call to SYSTEM_Initialize();.
    EUSART2_SetRxInterruptHandler(myEUSART2ISR);
    INTERRUPT_GlobalInterruptEnable();
    INTERRUPT_PeripheralInterruptEnable();
Now you need to write the myEUSART2 interrupt service routine. This function will check the incoming character from EUSART2 and append it to a global array of characters called IRrecieveBuffer. The last two characters of this array are the NULL character, '\0', followed by a checksum. After the EUSART2 ISR receives the checksum, the EUSART2 ISR should set a global flag, receiveNewMessage, to true. This will alert main that a new message has arrived. The following global variables and function declarations should be at the top of your program.
void myEUSART2ISR(void);
char IRrecieveBuffer[MAX_BUFFER_SIZE];
uint8_t receiveBusy = false;
uint8_t receiveNewMessage = false;


Checksum An 8-bit checksum for a string is the sum of the characters in the string modulo 256. By "modulo 256", I mean that is the sum were to get to 256, the sum rolls over to 0. You can calculate a sum modulo 256 as follows. If the sum is less than 256, leave it alone. If the sum is greater than 255, subtract sets of 256 until the sum is less than 256. This means that an 8-bit checksum will always be in the range [0-255]. The nice thing about addition of uint8_t datayped variables in the PIC microcontroller, is that any carry out from the MSB during addition is thrown-away. This makes addition of uint8_t variables modulo 256 by default without requiring any additional work on your part.

For example, the sum of the characters in the null terminated string "abc\0" is 97 + 98 + 99 + 0 = 294. However, if you computed this sum in a uint8_t typed variable, then 97 + 98 + 99 + 0 = 294 - 256 = 38.

Transmit
The transmit function will be handled using the same procedure used in the inLab. However, you will move the code from main into a function transmitCharacterOverIR. In order to be compatible with lab 7, make the array containing the transmitted string, IRtransmitBuffer, global. The following declarations should be at the top of your program.
char IRtransmitBuffer[MAX_BUFFER_SIZE];
void transmitCharacterOverIR(char letter, uint16_t baudRate);
In order to provide some level of fault detection in our communication protocol, you will append an 8-bit checksum to the end of the transmitted string (but after the NULL character). A checksum for a string is the numerical sum of the individual characters. For example, for the string "abc" the checksum is 97+98+99 = 294. But since this sum is being computed in an 8-bit variable, the check sum would actually be 294-256=38. For a more complex message like "This is a test" the checksum is 245. Note the terminating NULL character at the end of the string does not contribute to the checksum because its ASCII value is 0.

User Interface
At start-up your program should present a splash screen. The splash screen should also contain connection instruction for the development board (where to install jumper wires). When you press "?" you should be greeted with the following menu. Note that the "true" or "false" of receiveNewMessage should be printed along with the current Baud rate - you can take this code from the inLab.
-------------------------------------------------
1200 Baud
receiveNewMessage = true
-------------------------------------------------
?: help menu
o: k
Z: Reset processor
z: Clear the terminal
b: set the Baud rate of the sent characters
r: reset EUSART2
m: Enter in transmit Message
S: Send message in foreground
R: Receive message using EUSART2 ISR via IR decoder
-------------------------------------------------

Turn-in

You may work with a single partner (or alone) to complete this lab. Submit your main.c file on Canvas using the instructions posted there. You should take note of the Rubric that will be used to evaluate your assignment. Please form a group before submitting using the instructions posted on Canvas. You will demonstrate your code at the beginning of lab.