Introduction: Serial Debugging With CloudX

In this project, i am aiming at explaning the concept of debugging via the serial terminal. But first as a starter, lets explaing its concept through its meanings.

1. serial communication

serial communication is for communication between the CloudX board and a computer or other devices. All CloudX boards have at least one seen serial port (also known as a UART or USART): Serial. It communicates on digital RX and TX pin with other hardwares or serial communication modules (like gsm and gps ) as with the computer via USB using the SoftCard. Thus, if you use these functions, you cannot also use TX and RX for digital input or output. You can use the CloudX environment’s built-in serial monitor to communicate with an CloudX board. Click the serial monitor button in the toolbar and select the same baud rate used in the parameter called to serialBegin().

2. Debug

Debugging simply means identify and remove errors from (computer hardware or software).Debugging involves locating and correcting code errors in a computer program. Debugging is part of the software testing process and is an integral part of the entire software development lifecycle. Lets take for instance that your code has compiled successfully and you are testing your hardware and its not working as expected, although there are many ways to debug your code; a simple and effectice way to debug it is through the use of serial debugging. The CloudX IDE generates 2 types of file on sucessful compilation, HEX and COFF file. The HEX file is strictly machine code which is what is bootloaded into the board for execution in real world but can also run on your PC simulation softwares like Proteus Isis while the COFF file is a readable format executable on your PC simulation softwares (Proteus Isis). For this scope we will consider two basic types of debugging on serial protocol,

1. Soft Serial Debugging:

In this method, every test and debugging is done on the PC through some useful software like Proteus ISIS. Because the CloudX basically generate COFF file, I recommend using this for PC simulation because withit you can basically step between lines of codes and figure where a problem is coming from, and if your code must run without stepping, using virtual teminal from the "virtual instrument mode" tool, you can always know where which line is the controller is running at any given time. lets take a look at this code example,

Step 1:

/* 
 * File:   newmain.c
 * Author: OGBOYE GODWIN
 *
 * Created on June 28, 2018, 10:15 AM
 */
#include <cloudx m633.h="">
#include <cloudx serial.h=""></cloudx></cloudx>
/* we will make
red pin1
green pin2
yellow pin3
 *
 button pin4
*/
char *tell= "hmmm, i have been touch";
setup(){
    pinMode(1,OUTPUT);
    pinMode(2,OUTPUT);
    pinMode(3,OUTPUT);
    pinMode(4,INPUT);
    Serial_begin(9600);
    loop(){
        while(!readPin(4));
        Serial_writeText(tell);
        Serial_writeText("....moving to red");
        Serial_write(0x0D);
        portWrite(1,0x00);
        pinSelect(1, HIGH);
        delayms(200);       // try removing of commenting all delay and see what happens
                            // then replace them(you surely will love to!).
        
        while(!readPin(4));
        Serial_writeText(tell);
        Serial_writeText("....moving to green");
        Serial_write(0x0D);
        portWrite(1,0x00);
        pinSelect(2, HIGH);
        delayms(200);       // try removing of commenting all delay and see what happens
                            // then replace them(you surely will love to!).
        while(!readPin(4));
        Serial_writeText(tell);
        Serial_writeText("....moving to yellow");
        Serial_write(0x0D);
        portWrite(1,0x00);
        pinSelect(3, HIGH);
        delayms(200);       // try removing of commenting all delay and see what happens
                            // then replace them(you surely will love to!).
    }
}

with this you can see how the Serial debugging is important if you remove the delay's. if you did that you would have seen how troublesome that simple code can cause if it is executed in real world without those delay's.

Step 2:

2. Hardware Debugging:

In this method, every test and debugging is done by attaching the CloudX prototype board to the PC using the softCard and making use of either CloudX IDE's serial terminal (recommended) or some other useful software like Proteus ISIS compim, realTerm, etc. Generate COFF file cant be used here because this method demands HEX bootloaded into the hardware, I recommend using this for CloudX softcard. Note that your code run without stepping so you can always know where which line is the controller is running at any given time by the serial output. lets take a look at this code the same example listed above, setup your hardware to be similer to mine red LED --------- to pin1 green LED --------- pin2 yellow LED --------- pin3 button --------- pin4

Step 3:

steps

1. Use same code as above

2. bootload into your board

3. start the CloudX serial Terminal by clicking "serial" button in the tool bar

4. select desired port and baud rate(9600 in this tutorial)

5.start the terminal by clicking on connect(disconnect if you desire to quit)

6. with the port opened/connected,momentarily push the button at will and you will see the serial output shown on the terminal windows. Note that if you have the delays off the code, you will get multiple lines of serial output running in so fast without control before you take your hands off the button. If for any reason in your code, you have such or similar problem, you can always use this method to debug.

REGARDS