Jump to content
 

Search the Community

Showing results for tags 'debugging'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Top Level
    • Announcements
    • The Lounge
    • Questions and Answers
    • Forum Help
    • Project Gallery
    • Vendor Bug Reports

Blogs

  • What every embedded programmer should know about ...
  • Programming Lore
  • Toe-to-toe

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


About Me

Found 1 result

  1. One feature of MPLAB-X which is not nearly used enough is the Simulator. It is actually very powerful and useful for testing and debugging code which will run on your board and interact with the outside world via external stimuli. There is more information on the developer help site here http://microchipdeveloper.com/mplabx:scl This is how you can use the IDE to debug your serial command line interface code using stimulus files and the UART OUTPUT window. The first trick is to enable the UART output window in the IDE. We are going to start by creating a new project using MCC which drives the UART on the PIC16F18875. Settings should look as follows: Then go on the project settings and enable the UART output window in the simulator We can now update our main code to do something simple to test the UART output. #include "mcc_generated_files/mcc.h" uint8_t buffer[64]; void main(void) { // initialize the device SYSTEM_Initialize(); INTERRUPT_GlobalInterruptEnable(); INTERRUPT_PeripheralInterruptEnable(); printf("Hello World\r\n"); If you run this code in the simulator it will open an additional output window which will show the output from the UART as follows Now the next trick is to use a stimulus file to send your test data into the device via the UART to allow you to test your serial processing code. First we will make a test file, there is more information on the format of these files on the developer help site, but it is fairly easy to understand just by looking at the example. // Start off by sending 0x00 00 // First string, send the bytes H E L L O (no \0 will be sent) "HELLO" // Wait for 100 ms before sending the next bit wait 100 ms // Second string " WORLD" // Wait for 100 ms before sending the next bit wait 100 ms // Send an entirely binary packet 90 03 00 14 55 12 We now simply save this text file so that we can import it into the stimulus system. We will just call it data.txt for now. Next we have to set up the IDE to send the data in this file. We are going to start by opening the Stimulus editor, this is under the menu "Window | Simulator | Stimulus" in MPLAB-X. Navigate to the tab labeled "Register Injection" and do the following steps: To add the file we will enter a new row here. Just type in the empty boxes (or you can use the icons on the left to add a new row) Provide any label (we are using TEST) Select the UART1 Receive Register under Reg/Var - it is called RC1REG Choose "Message" for the trigger Click on the filename block to select the file we made above Set "Wrap" to no - this means it will not repeat Format should show Pkt and be raed-only The stimulus is now set up and ready for a test drive. As a test we are just going to update the program to echo back what it receives and we will be able to see the output in the Simulator Output window as the stimulus is being sent in. Here is the test code: #include <stdint.h> #include "mcc_generated_files/mcc.h" void main(void) { // initialize the device SYSTEM_Initialize(); INTERRUPT_GlobalInterruptEnable(); INTERRUPT_PeripheralInterruptEnable(); printf("Hello World\r\n"); while (1) { EUSART_Write(EUSART_Read()); } } If you now run the simulator the UART output will just show "Hello World" as the start message. When you hit the green run button on the stimulus it will send the data in the file to the program. Hitting the run button a second time will remove the stimulus and if you hit it one more time it will apply the stimulus a second time. That is a very basic introduction of how to use a stimulus which feeds data from a text file into the UART for testing purposes. It is a small step from here to feed data into a variable or into a different peripheral, we will not go into that right here, but know that it is easy to also do this. When you combine this feature with running MDB from the command line and using a test framework such as Unity http://www.throwtheswitch.org/unity/ you should have all the tools to create automated tests for your serial port code. As always the project with the code we used is attached. SimulatorUART.zip
×
×
  • Create New...