Serial Communication Between ESP32 and TI C2000 microcontroller

Dear All,

I am using TI C2000 microcontroller (28379D) to receive data from ES32.At the moment, the communication does not work.

  • The C2000 does not receive the expected data from ESP32.
  • ESP32 also does not receive data sent by the C2000.

. The code for the ESP32 is


The code for the TI C2000 microcontroller is:

Configuration SCIB is:

Connections:

  • ESP32 TX → C2000 SCIB RX
  • ESP32 RX → C2000 SCIB TX
    Thanks very much for your help.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

Please post your full sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post full error messages in code tags as it makes it easier to scroll through them and copy them for examination

Bearing in mind the forum category that you posted in, pleas confirm that you are using a Nano ESP32 rather than a generic ESP32 board

Thank you very much for the constructive feedback regarding my posting style, especially the advice on using code tags—I was unaware of that feature, but I have now read the guidelines and corrected my post accordingly. Thank you also for highlighting the distinction between the board types.

I have updated my code and my forum post. I'm posting my complete, current code below using code tags.
ESP32 DevKitC V4 Code (Receiver):
#include <HardwareSerial.h>

HardwareSerial esSerial(2); // UART2
int temperature ;
int humidity ;
int pressure ;
int t8;
uint8_t byteIndex = 0;
int values[6];
bool dataReady = false;
void setup()
{
Serial.begin(9600);
esSerial.begin(9600, SERIAL_8N1, 16, 17); // RX = GPIO16, TX = GPIO17
}
void loop() {
while (esSerial.available() > 0) {
uint8_t b = esSerial.read();
if (byteIndex < 4) {
values[byteIndex++] = b;
}
if (byteIndex == 4) {
for (int i = 0; i < 5; i++) {
if (values[i] == 1 && i + 1 < 4) {
temperature = values[i + 1];
} else if (values[i] == 2 && i + 1 < 4) {
humidity = values[i + 1]; }
// } else if (values[i] == 3 && i + 1 < 4) {
// pressure = values[i + 1];}
byteIndex = 0;
dataReady = true;
}
}}
// sendTemperatureToNextion();
// sendHumidityToNextion();
// sendPressureToNextion();
// sendT8();

COde F28379D(Transmitter):
//###########################################################################
//
// FILE: Example_2837xDSci_FFDLB_int.c
//
// TITLE: SCI Digital Loop Back with Interrupts.
//
//! \addtogroup cpu01_example_list
//!

SCI Digital Loop Back with Interrupts (sci_loopback_interrupts)


//!
//! This program uses the internal loop back test mode of the peripheral.
//! Other then boot mode pin configuration, no other hardware configuration
//! is required. Both interrupts and the SCI FIFOs are used.
//!
//! A stream of data is sent and then compared to the received stream.
//! The SCI-A sent data looks like this: \n
//! 00 01 \n
//! 01 02 \n
//! 02 03 \n
//! .... \n
//! FE FF \n
//! FF 00 \n
//! etc.. \n
//! The pattern is repeated forever.
//!
//! \b Watch \b Variables \n
//! - \b sdataA - Data being sent
//! - \b rdataA - Data received
//! - \b rdata_pointA - Keep track of where we are in the data stream.
//! This is used to check the incoming data
//!
//
//###########################################################################
//
// $Release Date: $
// $Copyright:
// Copyright (C) 2013-2023 Texas Instruments Incorporated - http://www.ti.com/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// $
//###########################################################################

//
// Included Files
//
#include "F28x_Project.h"

//
// Defines
//
#define CPU_FREQ 60E6
#define LSPCLK_FREQ CPU_FREQ/4
#define SCI_FREQ 100E3
#define SCI_PRD ((LSPCLK_FREQ/(SCI_FREQ*8))-1)

//
// Globals
//
//Uint16 sdataA[2]; // Send data for SCI-A
//Uint16 rdataA[2]; // Received data for SCI-A
//Uint16 rdata_pointA; // Used for checking the received data
Uint16 rdata;
Uint16 data;
Uint16 voltage, current;
Uint16 voltage1, current1;
void scib_xmit(int a);
int i;
int index;
int receiving;
Uint16 values[4];
Uint16 byteIndex = 0;
//
// Function Prototypes
//
interrupt void sciaTxFifoIsr(void);
interrupt void sciaRxFifoIsr(void);
interrupt void scibRxFifoIsr(void);
void scia_fifo_init(void);
void scib_fifo_init(void);
void error(void);

//
// Main
//
void main(void)
{

//
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
//
InitSysCtrl();

//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
//
InitGpio();

//
// For this example, only init the pins for the SCI-A port.
// GPIO_SetupPinMux() - Sets the GPxMUX1/2 and GPyMUX1/2 register bits
// GPIO_SetupPinOptions() - Sets the direction and configuration of the GPIOS
// These functions are found in the F2837xD_Gpio.c file.
//

// SCIB GPIO Init: GPIO18 = TX, GPIO19 = RX
GPIO_SetupPinMux(19, GPIO_MUX_CPU1, 2);
GPIO_SetupPinOptions(19, GPIO_INPUT, GPIO_ASYNC);
GPIO_SetupPinMux(18, GPIO_MUX_CPU1, 2);
GPIO_SetupPinOptions(18, GPIO_OUTPUT, GPIO_ASYNC);

//
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
DINT;

//
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2837xD_PieCtrl.c file.
//
InitPieCtrl();

//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
IER = 0x0000;
IFR = 0x0000;

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
//
InitPieVectTable();

//
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
//
EALLOW; // This is needed to write to EALLOW protected registers
// PieVectTable.SCIA_RX_INT = &sciaRxFifoIsr;
// PieVectTable.SCIA_TX_INT = &sciaTxFifoIsr;
PieVectTable.SCIB_RX_INT = &scibRxFifoIsr;
EDIS; // This is needed to disable write to EALLOW protected registers

//
// Step 4. Initialize the Device Peripherals:
//
scia_fifo_init(); // Init SCI-A
scib_fifo_init();
//
// Step 5. User specific code, enable interrupts:
//
// Init send data. After each transmission this data
// will be updated for the next transmission
//

//
// Enable interrupts required for this example
//
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER9.bit.INTx1 = 1; // PIE Group 9, INT1
PieCtrlRegs.PIEIER9.bit.INTx3 = 1; // PIE Group 9, INT2
IER = 0x100; // Enable CPU INT
EINT;

//
// Step 6. IDLE loop. Just sit and loop forever (optional):
//

while(1)
{
// scib_xmit(1);
// scib_xmit(voltage);
//
// scib_xmit(2);
// scib_xmit(current);

//}
}

//
// error - Function to halt debugger on error
//

//
// sciaTxFifoIsr - SCIA Transmit FIFO ISR
//
interrupt void sciaTxFifoIsr(void)
{
// Uint16 i;
//
// for(i=0; i< 2; i++)
// {
// SciaRegs.SCITXBUF.all=sdataA[i]; // Send data
// }
//sdataA[1]=60;
//sdataA[0]=20;
//
// SciaRegs.SCIFFTX.bit.TXFFINTCLR=1; // Clear SCI Interrupt flag
// PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ACK
}

//
// sciaRxFifoIsr - SCIA Receive FIFO ISR
//
interrupt void sciaRxFifoIsr(void)
{
// Uint16 i;
//
// for(i=0;i<2;i++)
// {
// rdataA[i]=SciaRegs.SCIRXBUF.all; // Read data
// }
//
//
// SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
// SciaRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
//
// PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ack
}

interrupt void scibRxFifoIsr(void)
{
// while (ScibRegs.SCIFFRX.bit.RXFFST > 0) {
// Uint16 rdata = ScibRegs.SCIRXBUF.all;
// if (byteIndex < 4){
// values[byteIndex++] = rdata;
// }
//
// if (byteIndex == 4)
// {
// int i;
// for ( i=0; i < 3; i++) {
// if (values[i] == 1 && i + 1 < 4) {
// voltage = values[i + 1];
// } else if (values[i] == 2 && i + 1 < 4) {
// current = values[i + 1];
// }
// }
// byteIndex = 0;
// }
// }
// ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
// ScibRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
//
// PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ack

}

//
// scia_fifo_init - Configure SCIA FIFO
//
void scia_fifo_init()
{
// SciaRegs.SCICCR.all = 0x0007; // 1 stop bit, No loopback
// // No parity,8 char bits,
// // async mode, idle-line protocol
// SciaRegs.SCICTL1.all = 0x0003; // enable TX, RX, internal SCICLK,
// // Disable RX ERR, SLEEP, TXWAKE
// SciaRegs.SCICTL2.bit.TXINTENA = 1;
// SciaRegs.SCICTL2.bit.RXBKINTENA = 1;
// SciaRegs.SCIHBAUD.all = ((uint16_t)SCI_PRD & 0xFF00U) >> 8U;
// SciaRegs.SCILBAUD.all = (uint16_t)SCI_PRD & 0x00FFU;
// SciaRegs.SCICCR.bit.LOOPBKENA = 1; // Enable loop back
// SciaRegs.SCIFFTX.all = 0xC022;
// SciaRegs.SCIFFRX.all = 0x0022;
// SciaRegs.SCIFFCT.all = 0x00;
//
// SciaRegs.SCICTL1.all = 0x0023; // Relinquish SCI from Reset
// SciaRegs.SCIFFTX.bit.TXFIFORESET = 1;
// SciaRegs.SCIFFRX.bit.RXFIFORESET = 1;
}

void scib_fifo_init()
{
ScibRegs.SCICCR.all = 0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScibRegs.SCICTL1.all = 0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
ScibRegs.SCICTL2.bit.TXINTENA = 0;
ScibRegs.SCICTL2.bit.RXBKINTENA = 1;
ScibRegs.SCIHBAUD.all = 0x0002;
ScibRegs.SCILBAUD.all = 0x008B;
ScibRegs.SCICCR.bit.LOOPBKENA = 0; // Enable loop back
ScibRegs.SCIFFTX.all = 0xC022;
ScibRegs.SCIFFRX.all = 0x0022;
ScibRegs.SCIFFCT.all = 0x00;

ScibRegs.SCICTL1.all = 0x0023; // Relinquish SCI from Reset
ScibRegs.SCIFFTX.bit.TXFIFORESET = 1;
ScibRegs.SCIFFRX.bit.RXFIFORESET = 1;
}

void scib_xmit(int a)
{
while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {} //#0 no empty yet not transmit
ScibRegs.SCITXBUF.all=a;
}
//
// End of file
//

I moved your topic to a more appropriate forum category @nowis.

In the future, when creating a topic please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

You did not. Please read the forum guide once again to learn how to correctly post code here on Arduino Forum.

can you give a link to the specific TI C2000 microcontroller?

are you using a development board or built your own PCB?

are you using the LAUNCHXL-F28379D ?

Hi horace, sorry for the late reply.
I’m using the TI C2000 F28379D microcontroller. Currently, I’m working with the development board (LAUNCHXL-F28379D).

the LAUNCHXL-F28379DOverview documentation shows UART connections on J1 Rx GPIO19 and Tx GPIO18

can you use this UART to connect to the ESP32 Serial1 hardware port?

initially probably worth trying to connect a USB-TTL 3.3V to the GPIO 18 and 19 and see if you can communicate with it, e.g. FTDI TTL-232R-3V3

Hi horace, sorry for the late reply.
I’m currently using those UART pins (GPIO18 as Tx and GPIO19 as Rx) for communication, and they’re already configured in my CCS code for the F28379D. However, I still haven’t figured out why the F28379D and the ESP32 are not transmitting data successfully, even though I’m sending the data in this frame:
scib_xmit(1);
scib_xmit(voltage);
scib_xmit(2);
scib_xmit(current);
Im truly struggling about this problems.

could be

  1. TI not transmitting/receiving
  2. ESP32 not receiving/transmitting
  3. incorrect connections

how have you connected the devices?
what ESP32 code are you using?
do you have an oscilloscope to check if there are any serial signals?
can you connect TI GPIO18 and GPIO19 together and do a loopback test?

Can you get either side to work by itself using just a terminal emulator like PuTTY or Coolterm?

a7

I connected the TX pin of the F28379D to the RX pin of the ESP32, the RX pin of the F28379D to the TX pin of the ESP32, and both devices share a common GND..
The code for ESP32 ( Received )
void loop() {
while (esSerial.available() > 0) {
uint8_t b = esSerial.read();
if (byteIndex < 4) {
values[byteIndex++] = b;
}
if (byteIndex == 4) {
for (int i = 0; i < 5; i++) {
if (values[i] == 1 && i + 1 < 4) {
temperature = values[i + 1];
} else if (values[i] == 2 && i + 1 < 4) {
humidity = values[i + 1]; }
// } else if (values[i] == 3 && i + 1 < 4) {
// pressure = values[i + 1];}
byteIndex = 0;
dataReady = true;
Im haven;t checked serial signal yet by using oscilloscope

I haven’t used those terminal applications like PuTTY or CoolTerm yet. Do you have nay introduction about any these applications ?

which GPIO pins have you used on the ESP32
here is some test code to use the Serial1 hardware serial port on GPIO16 and 17

// ESP32  Serial1 test - for loopback test connect pins RXD1 and TXD1

#define RXD1 16 // can map Serial1 and Serial2 to many ESP32 GPIO pins
#define TXD1 17 // check pin usage https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

// for RS232 shield connect
// ESP32 RXD1 to TTL/RS232 Rx
// ESP32 TXD1 to TTL/RS232 Tx
// connect GND pins together and VCC to 3.3V on ESP32 5V on UNO ect
// for loopback test connect 9-pin D_type connector pins 2 Tx to 3 Rx (pin 5 is GND)

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial1.begin(9600, SERIAL_8N1, RXD1, TXD1);
  Serial.printf("\n\nESP32 serial1  test RXD1 pin %d TXD1 pin %d\n", RXD1, TXD1);
  Serial.printf(" loopback test connect pin %d to pin %d\n", RXD1, TXD1);
  Serial.printf("RS232: ESP32 pin %d RXD1 to TTL/RS232 Rx and pin %d TXD1 to TTL/RS232 Tx\n", RXD1, TXD1);
  Serial.printf("RS232 - loopback connect 9-pin D-type pin 2 Tx to pin 3 Rx\n");
}

void loop() {
  // read from Serial1, send to Serial
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }
  // read from Serial, send to Serial1
  if (Serial.available()) {
    int inByte = Serial.read();
    //Serial.write(inByte);     // local echo if required
    Serial1.write(inByte);
  }
}

ESP32 serial monitor output

ESP32 serial1  test Rx pin 16 Tx pin 17
   for loopback test connect pin 16 to pin 17
loopback test 1
loopback test 2 abcdefghijk 000000000000000
hello from mega
test 2 from mega
test 3 from mega 1234567890


which is connected to an arduino mega


Arduino Mega Serial1 test -  for loopback test connect pin 18 to pin 19
RS232: Mega pin 18 TXD to TTL/RS232 Tx and pin 19 RXD to TTL/RS232 Rx
RS232 - loopback connect 9-pin D-type pin 2 Tx to pin 3 Rx

loopback test1
loopback test 2 1234567890 llllllllllll
hello from ESP32
test 2 from esp32
test 3 from ESP32 12345678900987654321

Do you happen to have any sample code to test UART communication between the ESP32 and the F28379D?. Thanks a lot for ur time

got many dev boards but not a Ti F28379D

for the ESP32 try the code of post 14
connect TI GPIO18 Tx to ESP32 GPIO16 Rx
connect TI GPIO19 Rx to ESP32 GPIO17 Tx
run your Ti code
does anything appear on ESP32 serial monitor?
ensure baudrates etc are the same

I need a sample frame format so that the ESP32 and the F28379D can communicate properly.”
My frame using to communication is:
1Current2Voltage

initially just send simple text
when that works you can start experimenting

Would it be okay if you had some communication apps? I’d love to ask you more things if you don’t mind

not sure what you mean by "communication apps"

are you thinking of terminal emulators such as "PuTTY or CoolTerm" mentioned by @nowis in post 13 which can be used to communicate with USB-RS232 and USB-TTL serial devices (make sure you use the correct voltage levels RS232, 5V or 3.3V or even RS485)

I tend to use TeraTerm and realTerm on Windows and Putty on Linux and Raspberry Pi

ask any questions - there are plenty of people ready to help