Create a TCP application using the SIM800 module and a FRDM Kinetis® K64 MCU board based on FreeRTOS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create a TCP application using the SIM800 module and a FRDM Kinetis® K64 MCU board based on FreeRTOS

Create a TCP application using the SIM800 module and a FRDM Kinetis® K64 MCU board based on FreeRTOS

About this demo

This demo was created to give you a headstart for a UART - based GPRS module. The goal was to build the project on top of FreeRTOS ensuring a good implementation for task management and adaptability for any other project based on AT commands using a UART module. 

According to the documentation of the module, the SIM800L from SIMCOM is controlled via AT commands. The advantage of using these commands is that, by tweaking some of the tasks, the application can be used for any other AT command based module.

In this demo I'm going to walk you through the key elements that were used and give you a functional project that has the addition of working on a FreeRTOS environment. This offers great reliability for a fully working application that won't hang for an untested reason. Exploring this project should give you a good idea of how semaphores are implemented for various tasks management depending on each priority.

Project Scope

  • The project is intended to work with a SIM800L connected to a Freedom Development Platform for Kinetis® K64 through UART.
  • Due to the high current consumption during some functions, the SIM800 module requieres a >1200mAh battery or a >2A buck converter.
  • This GPRS module is a low-cost item but requires a 2G SIM card to work properly. This might be complicated to obtain in some countries.
  • The project was built using the MCUXpresso SDK's FreeRTOS UART example.

Useful Links

Link Description
https://mcuxpresso.nxp.com/en/builder SDK Builder for the Kinetis K64
https://www.simcom.com/product/SIM800.html SIMCOM SIM800 site documentation
https://www.freertos.org/xSemaphoreCreateBinary.html FreeRTOS

 

Required Items

Link Description
https://www.nxp.com/design/development-boards/freedom-development-boards/mcu-boards/freedom-developm... NXP's FRDMK64 Board
https://simcom.ee/modules/gsm-gprs/sim800/ SIMCOM SIM800 GPRS Module
Buck converter  
Power supply to deliver up to 4.3 V and 2 Amps  
Cellular antenna  

 

Hardware Diagram

  • Due to the SIM800 module's high current consumption, powering it requires a buck converter that is capable of delivering a current larger than 2 Amps while the module is sending a message. This is when the module consumes the highest current.

   SIM 800L  ===>    FRDM K64

        VCC    ===>    3V9 Buck Converter

          RX     ===>    TX (PTC17/J1-4)

          TX     ===>    RX (PTC16/J1-2)

       GND    ===>    GND

Diagram1.png

 

Step-by-Step Guide for testing the Demo

  1. Get the K64 SDK from https://mcuxpresso.nxp.com/en/select
    1. Fabian_R_0-1612823803859.png

       

  2. Get the latest version of MCUXpresso using this link: https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/mcuxpresso-i...
    1. Fabian_R_1-1612823917368.png
  3. Get the SIM800 AT commands documentation in this link: https://www.elecrow.com/wiki/images/2/20/SIM800_Series_AT_Command_Manual_V1.09.pdf
  4. Install the K64 SDK in MCUXpresso.
  5. Import the attached project in this document. 

Attachments are found at the bottom of this document.

  1. Fabian_R_3-1612824100776.png
  1. Connect the K64 through the USB cable.
  2. Connect the SIM800L as indicated in the previous chapter: Diagram.
  3. Build and Debug the project using MCUXpresso.
  4. In the console, you should be able to see the flow of the Tasks that are being executed. Also, the commands that are being sent and received by the UART.
  5. Due to the TaskDelay from the send_task, the application will execute every 10,000 ticks. This depends entirely on the portTick_PERIOD_MS, in this case, which in this case is roughly every 25 seconds.

Additional Demo Information

These next steps are intended to guide the developer to an easier understanding of the modifications that were made from the base project.

This additional information intends to give you a greater understanding of how the project was built and a further explanation of the different topics this application needs for its implementation.

The usage of FreeRTOS wasn't mandatory, but the usage of an operative system gives the application an additional layer of reliability for safe deployment. In addition to the actual tasks, you could implement a new task for an OTA update for new drivers, a fully functional response parser, or any other addition depending on your project needs. The usage of a task-based project ensures flexibility of the project since many modifications will not require a complete rebuilding of the application. As mentioned before, the implementation of semaphores will provide reliable task management depending on the required function.

Diagram2.png

The project started from the freertos_uart example and from there three additional tasks were built: a connect task, send task, and a check task. Here is a brief explanation of each task to provide a full understanding of the functionality. 

  1. uart_task()
    1. This task was only slightly modified. The UART was changed to the UART3 interface.
    2. The UART_RTOS_Send() and UART_RTOS_Receive() functions are in the loop because the semaphore implementation is doing the release of retainment of the different tasks based on their priority.
    3. Priority is very important for this project because based on its priority the application flow would be affected. uart_task() has the highest priority. This will ensure that every time a new command is required to be sent, the application will retain the actual task and release the uart task.
    4. At the end of this task, a new semaphore is called. This semaphore will call the check_task() whose functionality is to compare the received string to the expected one.
  2. check_task()
    1. This task is executed right after the buffer has received the number of bytes that were expected from the function parameters.
    2. The first step of this task is to eliminate the extra characters ´\n´ and ´\r´ that compose the SIM800 module answer message.
    3. Depending on the command sent, the task compares the response in order to look for an Error response or a positive one. This might be different than a simple OK, depending on the command.
  3. connect_task()
    1. This task is called when the SIM800 module is disconnected. This implementation is a simple string copy that use semaphores to call the task uart and then the check task compares the received string.
    2. After the module returns an IP address, the semaphore gives the order to call the send task to continue the application flow.
  4. send_task()
    1. This task has the least priority but is the first one created, it calls the sendRoutine() function which intends to gather the data to be sent.
    2. This connect task is triggered when a command that expects an IP address, returns an ERROR response. The command sent is AT+CIFSR plus the response comparison. The application flow enters to an if conditional that calls a semaphore for the connect_task() routine.
    3. Then, the frame to be sent through the TCP function of the SIM800 module is built.
    4. Due to the protocol chosen, the SIM800 module expects a response from the server, specifically a 200 HTTP code.
    5. Depending on your module, this is where the protocol modifications can be done.

A point that is worth mentioning is that the module works in a 2G bandwidth. This can be a problem in some countries due to the SIM card version incompatibility between your area network and the module. If this is the case in your country, I strongly recommend looking for a 4G module like the SIM7080 or any other NB-IoT module. This might be more expensive but you are ensuring your project will work on top of the newest cellular bands.

 

 

Attachments
No ratings
Version history
Last update:
‎02-16-2021 03:19 PM
Updated by: