UART Cross Connect Interrupt 2
Overview
The purpose of the project is to transfer the "Hello World" string from UART 1 to UART 4 and to transfer the
"I hear you" string in the opposite direction. Your code must confirm that the received strings match the transmitted strings.
This project uses the same cross connect as the cross connect polling project. The sample code is in myCourses
in the Content area in Zhu_text_537-539.pdf. Also, refer to the UART slides.
Setup
Make a copy of your UART cross connect polling code and then start implementing the interrupt logic.
Requirements
- Copy the UART interrupt code setup from page 537 into function called UART_Interrupt_Enable().
This needs to also set up UART 4 as well (all four lines).
- Use the receive buffer size of 81 (80 plus end of string).
- Use two receive buffers (one for each UART).
- Copy the interrupt handlers and helper functions for both UARTs from pages 538 and 539.
- For the send function change the code to look for a 0 byte (the end of string) to stop the transmission after
sending that byte.
- Note that you will have to combine the send and receive interrupt service code into one ISR per UART.
To do this easily create two boolean flags called uart1_send and uart4_send. These boolean values
must be true ONLY when a send is in progress. The last send interrupt (when we send a 0 byte) must
both turn off the transmit empty interrupt and must clear the corresponding boolean flag.
- All of your code must be in uart_cross_interrupt.c.
(This is for ease of submission and grading -- please use modular design!)
- Whenever possible hide as much as possible using the static keyword (such as counters and buffers)
- Create a testing function, interrupt_tests(), that is called from main. This function should be
declared in uart_cross_interrupt.h. This header needs to be included by main.c so the linker will connect
the reference in main.c to the function in uart_cross_interrupt.c.
- Your transmit and receive code MUST use interrupts to transfer the data.
- Calls UART_Interrupt_Enable().
- Calls send_hello_world() unit test.
This test transmits the string using UART 1.
This test verifies that UART 4 receive buffer gets the expected "Hello World" string.
Be sure to send the 0 at the end of the string to indicate the end of the transmission.
- Calls send_I_hear_you() unit test.
This test transmits the string using UART 4.
This verifies that UART 1 receive buffer gets the expected "I hear you" string.
Be sure to send the 0 at the end of the string to indicate the end of the transmission.
- Lights red LED if either test fails.
- Lights green LED if both pass.
- The code waits for the down button to be pressed. When it is pressed
the send_hello_world() and send_I_hear_you() functions must be executed again.
- NOTE -- your test functions must handle the removal of one of the jumper wires. This means
you must have some sort of timeout that causes each of your unit tests to fail. This
should not exceed 2 seconds.
Hints and Tips
This section provides specific recommendations on successfully implementing this project.
- The UART Interrupt Enable code from page 537 of the text is fine. Just duplicate it for UART4.
- NOTE: Be sure to include the NVIC_SetPriority() and NVIC_EnableIRQ() function calls for both UARTs.
- The two IRQHandler routines call both send() and receive().
- You do not need to add a boolean flag to control calls to send().
The better solution is to change the first line in send(). It needs to verify that
the transmit interrupt bit is enabled. Change the first line in send() to:
if( ( USARTx->CR1 & USART_CR1_TXEIE ) && ( USARTx->ISR & USART_ISR_TXE ) )
- The textbook's version of UART_Send needs changed:
- Add code to copy the passed string to your global transmit buffer (strcpy works).
- Do not load any data into the TDR. When you enable the interrupt the IRQHandler will
send the first byte. Enabling the interrupt must be the last line in this function.
- This is also a good place to set your transmit counter to zero.
- In send() because you are now sending all of the data from this code you don't increment
your counter until after you send the next character.
- in send() detect when you send the 0 byte (the end of string marker) and turn off the transmit
empty interrupt. You may need to wait for the Transmit Complete bit (TC) to be set in the ISR
before you turn off the empty interrupt. See the next two lines for the code to do this.
- while ( ! USARTx->ISR & USART_ISR_TC ) ;
- USARTx->CR1 &= ~USART_CR1_TXEIE;
- For your unit testing be sure to allow enough time for the string to be sent. 50 ms is plenty of time.
You can use the USART_Delay function to accomplish this. Insert the delay after you have started
the transmission of the string and before you check for successful reception.
- To check for successful completion use strcmp() to
compare the string you sent to the string in the other UARTs receive buffer. The test passes
only the strcmp returns a 0 indicating an exact match. You may want to added your receive
buffers to a watch window in the Keil debugger.
References
Rubric
Rubric is defined in the demo sheet
- UART Cross Interrupt Review
- Late penalties of 5% per day apply based on when you submit your final code to the Dropbox.
- Demos will be accepted in class through the last class session. Any penalties will be based
on the date and time of your Dropbox submission.
Submission
Only submit uart_cross_interrupt.c and uart_cross_interrupt.h to the UART Cross Interrupt myCourses folder.