This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28379D: Codes

Part Number: TMS320F28379D


Hi Experts,

Our customer have a problem in serial communication between TMS320F28379D conrolCard and Nextion display, he based on sci_ex2_loopback_interrupts example to start and he can send data to the nextion display but he can't read from it.
Below is his code for reading information comming from the display. The code is working if he use Arduino card to send the command but it doesn't it he try to read command comming over serial from the Nextion display.
If you have any ideas that can help our customer please, thank you in advance.


//*********************************************************************************
/*TM320F28379D SCIA communication with Nextion*/
//*********************************************************************************
//
//***************************Included Files*******************************
//
#include<stdio.h>
#include<stdlib.h>
#include <string.h>

#include "F28x_Project.h"
#include <F2837xD_device.h>
#include <F2837xD_Examples.h>

#include <device.h>
#include<driverlib.h>
#include<sci.h>

//
//******************************Defines*************************************
#define BLINKY_LED_GPIO 31
#define BUFFER_SIZE 128
//#define DEVICE_LSPCLK_FREQ (DEVICE_SYSCLK_FREQ / 4)
//******************************Globals*************************************
uint16_t counter = 0;
unsigned char *msg;
uint16_t rec=0;
uint16_t rdata_pointA=0;
unsigned char rdataA[BUFFER_SIZE];
char Rx_array[128];
//**************************Prototypes**************************************
void UART_GPIO_init();
void SCI_A_init();
void config_SCIA();
void initSCIAFIFO();
__interrupt void sciaTxISR(void);
__interrupt void sciaRxISR(void);


//**************************************************************************
//

void main(void)
{

//
InitSysCtrl();
//

InitGpio();
GPIO_SetupPinMux(BLINKY_LED_GPIO, GPIO_MUX_CPU1, 0);
GPIO_SetupPinOptions(BLINKY_LED_GPIO, GPIO_OUTPUT, GPIO_PUSHPULL);
//
Device_init();
Device_initGPIO();
//UART_GPIO_init();
//config_SCIA();
//SCI_A_init();
//
// ***********************Loop blink LED test*************************
//
int i;
for(i=0;i<10;i++)
{
//
// Turn on LED
//
GPIO_WritePin(BLINKY_LED_GPIO, 0);
//
// Delay for a bit.
//
DELAY_US(1000*100);
//
// Turn off LED
//
GPIO_WritePin(BLINKY_LED_GPIO, 1);

//
// Delay for a bit.
//
DELAY_US(1000*100);
}

GPIO_WritePin(BLINKY_LED_GPIO, 0);
//
//************************SCI Interrupt ************************
DINT;

UART_GPIO_init();
config_SCIA();
SCI_A_init();
//
// Initialize interrupt controller and vector table.
//
Interrupt_initModule();
Interrupt_initVectorTable();
IER = 0x0000;
IFR = 0x0000;

//
// Map the ISR to the wake interrupt.
//
Interrupt_register(INT_SCIA_TX, sciaTxISR);
Interrupt_register(INT_SCIA_RX, sciaRxISR);

//
// Initialize SCIA and its FIFO.
//
// initSCIAFIFO();
// SCI_performSoftwareReset(SCIA_BASE);
// msg = "\r\n\n\nHello World!\n";
// SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 17);
// msg = "\r\nYou will enter a character, and the DSP will echo it back!\r\n";
// SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 62);

//
// Clear the SCI interrupts before enabling them.
//
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);

//
// Enable the interrupts in the PIE: Group 9 interrupts 1 & 2.
//
Interrupt_enable(INT_SCIA_RX);
Interrupt_enable(INT_SCIA_TX);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);

//
// Enable global interrupts.
//
EINT;
ERTM;
//

//**************************Interrupt loop***************************
while(1){;}
//*******************************************************************

}//End main
//

//****************************************************
void UART_GPIO_init(){

//SCIA -> SCI0 Pinmux
// GPIO_setPinConfig(GPIO_43_SCIRXDA);
// GPIO_setPinConfig(GPIO_42_SCITXDA);

GPIO_SetupPinMux(28, GPIO_MUX_CPU1, 1);
GPIO_SetupPinOptions(28, GPIO_INPUT, GPIO_PUSHPULL);//GPIO_PUSHPULL to GPIO_PULLUP
GPIO_SetupPinMux(29, GPIO_MUX_CPU1, 1);
GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC);//GPIO_ASYNC to GPIO_PULLUP

// GPIO_setPinConfig(GPIO_28_SCIRXDA);// DEVICE_GPIO_CFG_SCIRXDA to GPIO_28_SCIRXDA
// GPIO_setPinConfig(GPIO_29_SCITXDA);//DEVICE_GPIO_CFG_SCITXDA to GPIO_29_SCITXDA
}
//***************************************************
void SCI_A_init(){

SCI_performSoftwareReset(SCIA_BASE);

//
// Configure SCIA for echoback.
//
SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 |SCI_CONFIG_STOP_ONE |SCI_CONFIG_PAR_NONE));
SCI_resetChannels(SCIA_BASE);
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);
SCI_enableModule(SCIA_BASE);
SCI_performSoftwareReset(SCIA_BASE);

//
// Enable the TXRDY and RXRDY interrupts.
//
SCI_enableInterrupt(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);

#ifdef AUTOBAUD
//
// Perform an autobaud lock.
// SCI expects an 'a' or 'A' to lock the baud rate.
//
SCI_lockAutobaud(SCIA_BASE);
#endif
}
//**************************************************************
void config_SCIA()
{
// Configuration for the SCI Rx pin.
//
GPIO_setMasterCore(DEVICE_GPIO_PIN_SCIRXDA, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_28_SCIRXDA);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(DEVICE_GPIO_PIN_SCIRXDA, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_QUAL_ASYNC);

//
// Configuration for the SCI Tx pin.
//
GPIO_setMasterCore(DEVICE_GPIO_PIN_SCITXDA, GPIO_CORE_CPU1);
GPIO_setPinConfig(GPIO_29_SCITXDA);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(DEVICE_GPIO_PIN_SCITXDA, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_QUAL_ASYNC);

//
// Initialize interrupt controller and vector table.
//
Interrupt_initModule();
Interrupt_initVectorTable();

//
// Initialize SCIA and its FIFO.
//
SCI_performSoftwareReset(SCIA_BASE);

//
// Configure SCIA for echoback.
//
SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 |
SCI_CONFIG_STOP_ONE |
SCI_CONFIG_PAR_NONE));
SCI_resetChannels(SCIA_BASE);
SCI_setFIFOInterruptLevel(SCIA_BASE, SCI_FIFO_TX2, SCI_FIFO_RX2);// RX and TX FIFO Interrupts Enabled
SCI_resetRxFIFO(SCIA_BASE);
SCI_resetTxFIFO(SCIA_BASE);
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF | SCI_INT_RXFF);
SCI_enableFIFO(SCIA_BASE);
SCI_enableModule(SCIA_BASE);
SCI_performSoftwareReset(SCIA_BASE);
//

#ifdef AUTOBAUD
//
// Perform an autobaud lock.
// SCI expects an 'a' or 'A' to lock the baud rate.
//
SCI_lockAutobaud(SCIA_BASE);
#endif

}
// ******************* initSCIAFIFO - Configure SCIA FIFO*************
void initSCIAFIFO()
{
//
// 8 char bits, 1 stop bit, no parity. Baud rate is 9600.
//
SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 |
SCI_CONFIG_STOP_ONE |
SCI_CONFIG_PAR_NONE));
SCI_enableModule(SCIA_BASE);
SCI_enableLoopback(SCIA_BASE);
SCI_resetChannels(SCIA_BASE);
SCI_enableFIFO(SCIA_BASE);

//
// RX and TX FIFO Interrupts Enabled
//
SCI_enableInterrupt(SCIA_BASE, (SCI_INT_RXFF | SCI_INT_TXFF));
SCI_disableInterrupt(SCIA_BASE, SCI_INT_RXERR);

SCI_setFIFOInterruptLevel(SCIA_BASE, SCI_FIFO_TX2, SCI_FIFO_RX2);
SCI_performSoftwareReset(SCIA_BASE);

SCI_resetTxFIFO(SCIA_BASE);
SCI_resetRxFIFO(SCIA_BASE);

#ifdef AUTOBAUD
//
// Perform an autobaud lock.
// SCI expects an 'a' or 'A' to lock the baud rate.
//
SCI_lockAutobaud(SCIA_BASE);
#endif
}
//*****************************Interrupt**************************

__interrupt void
sciaTxISR(void)
{

//
// Disable the TXRDY interrupt.
//
SCI_disableInterrupt(SCIA_BASE, SCI_INT_TXRDY);

// msg = "\r\nEnter a character: \0";
// SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 22);

//
// Ackowledge the PIE interrupt.
//
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}

//
// sciaRxISR - Read the character from the RXBUF and echo it back.
//
__interrupt void
sciaRxISR(void)
{


////******************To sent an Array of characters*****************************
//
rdataA[rdata_pointA]=SciaRegs.SCIRXBUF.all;
rdata_pointA++;

if(rdata_pointA>=BUFFER_SIZE)
rdata_pointA=0;

//if(rdataA[rdata_pointA-1]=='\n')
if((rdataA[rdata_pointA-1]=='F')&&(rdataA[rdata_pointA-2]=='F')&&(rdataA[rdata_pointA-3]=='x')&&(rdataA[rdata_pointA-4]=='0')&&(rdataA[rdata_pointA-5]=='F')&&(rdataA[rdata_pointA-6]=='F')&&(rdataA[rdata_pointA-7]=='x')&&(rdataA[rdata_pointA-8]=='0')&&(rdataA[rdata_pointA-9]=='F')&&(rdataA[rdata_pointA-10]=='F')&&(rdataA[rdata_pointA-11]=='x')&&(rdataA[rdata_pointA-12]=='0'))
{
//SCI_writeCharArray(SCIA_BASE,(uint16_t *)"from DSP to Arduino you sent:\r\n", sizeof("from DSP to Arduino you sent:\r\n"));
SCI_writeCharArray(SCIA_BASE, (uint16_t*)"\r\n", sizeof("\r\n"));//added
SCI_writeCharArray(SCIA_BASE, (uint16_t*)rdataA, rdata_pointA-12);
//memset(rdataA,'\0',128);
rdata_pointA=0;
}
PieCtrlRegs.PIEACK.all=0x100;
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
//
////*********************To sent a character*******************************************************
// uint16_t receivedChar;
//
// // Enable the TXRDY interrupt again.
// //
// SCI_enableInterrupt(SCIA_BASE, SCI_INT_TXRDY);
//
// //
// // Read a character from the RXBUF.
// //
// receivedChar = SCI_readCharBlockingNonFIFO(SCIA_BASE);
//
// //
// // Echo back the character.
// //
// /*msg = " You sent: \0";
// SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 13);*/
// SCI_writeCharArray(SCIA_BASE, (uint16_t*)"\r\n", sizeof("\r\n"));//added
//// if(receivedChar==13)SCI_writeCharArray(SCIA_BASE, (uint16_t*)"\r\n", sizeof("\r\n"));//added
// SCI_writeCharBlockingNonFIFO(SCIA_BASE, receivedChar);
//
//
// //
// // Acknowledge the PIE interrupt.
// //
// Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
//
// counter++;
}

Kind regards,
Gerald

  • Hi Gerald,

    The code is working if he use Arduino card to send the command but it doesn't it he try to read command comming over serial from the Nextion display.

    Have they probed the RX pin to ensure data is being sent from the Nextion display?

    he can send data to the nextion display but he can't read from it.

    Is the count in the RX interrupt increasing? If so, is it that the data is incorrect?

    Best Regards,

    Marlyn

  • Hi Marlyn,

    Have they probed the RX pin to ensure data is being sent from the Nextion display?
    Yes, customer used the Nextion display with Arduino and the communication is fine he can read and write. Also when he use the F28379D controlcard with Arduino he can read and write, but when he use the Nextion with F28379D card he can send commands to the display but he can't read from it.

    Is the count in the RX interrupt increasing? If so, is it that the data is incorrect?
    No the interrupt counter doesn't increase and nothings appear in the RX buffer, also he use a LED blink if an interrupt comes through RX but the LED doesn't blink

    Kind regards,
    Gerald

  • Gerald,

       Marlyn is currently out-of-the-office and will respond when she is back in the office on Monday. Thank you for your patience.

  • Hi Gerald,

    Thank you for your responses.

    I see that the customer is disabling the RX error interrupt. Would it be possible to enable this and insert an if statement into the rx interrupt to check for any errors? This could give us more insight as to why there is no data being received from the Nextion display. If there are errors, lets check what kind of errors (framing, break detect, etc.). 

    Also, is there anything different about the RX path (hardware-wise) while using the Nextion display?

    Best Regards,

    Marlyn

  • Hi Marlyn,

    About the RX error interrupt, customer said that he will add it and will let us know.
    He also mentioned that the communication is good when he connect the DSP to Arduino for reading and writing he think there is no problem with the RX error interrupt.
    Also, the Nextion display is working with Arduino in both reading and writing.
    Another thing the TX out from the Nextion display is between 3V and 5V is the F28379D DSP can handle this voltage level or do he need a 3.3V to 5V converter?

    Kind regards,
    Gerald

  • Hi Marlyn,

    I see that the customer is disabling the RX error interrupt.
    Please which error interrupt do you mean? is it the "void error(void)" function?

    Kind regards,
    Gerald

  • Hi Gerald,

    Through these lines:

    He also mentioned that the communication is good when he connect the DSP to Arduino for reading and writing he think there is no problem with the RX error interrupt.

    If they enable the SCI_INT_RXERR, then the interrupt will also occur anytime there is an error. A breakpoint can be inserted when the RX interrupt is reached and then take a look at the SCIRXST register.

    Another thing the TX out from the Nextion display is between 3V and 5V is the F28379D DSP can handle this voltage level or do he need a 3.3V to 5V converter?

    The F28379D pins can only handle 3.3V not 5V. If the output of the Nextion is 5V then this will need to be converted down.

    Best Regards,

    Marlyn

  • Hi Marlyn,

    Please refer to details below for customer feedback:

    "I enabled the SCI_INT_RXERR, and I added an if statement into the rx interrupt to check for errors in the __interrupt void
    sciaRxISR(void) function. Also, add the SCIRXST register to the watch expression window but I get nothing.

    // RX and TX FIFO Interrupts Enabled
    SCI_enableInterrupt(SCIA_BASE, (SCI_INT_RXFF | SCI_INT_TXFF));
    SCI_enableInterrupt(SCIA_BASE, SCI_INT_RXERR);// enable SCI_INT_RXERR

    // if statement into the __interrupt void sciaRxISR(void) function
    if(SCI_INT_RXERR)
    {
    //error();
    GpioDataRegs.GPATOGGLE.bit.GPIO31 = 1;//toggle a LED after interrupt
    }

    Otherwise, I use a 3.3V to 5V Bi-Directional Logic Level Converter between F28379D controlcard and the Nextion display, but still the same thing I can send data to the display but I can't read from it.

    Another thing I'm working now on a logic analyzer to see the frame sending by the display and it's the same as that sending by arduino"

    Kind regards,
    Gerald

  • Hi Gerald,

    Thank you for sending over the feedback from the customer. I appreciate them implementing the rx error interrupt. 

    Another thing I'm working now on a logic analyzer to see the frame sending by the display and it's the same as that sending by arduino"

    Is this something being worked on or the result was that the output of the display was the same as the arduino? 

    Would it be possible to provide scope captures of the output being sent from the arduino and from the display? Additionally, has the RX pin been probed on the F28379D device to at least confirm that the data is making it onto the pin? 

    Best Regards,

    Marlyn

  • Marlyn

    Please refer to details below for customer feedback:

    "
    I'm sorry for not being very clear, I mean by "frame sending by the display and it's the same as that sending by Arduino" that the Tx output of the display is the same as the Tx output of Arduino but doesn't work, I mean doesn't work with the display but it worked with arduino.

    Find attached the scope captures of the output being sent from the Arduino and from the display, I print "0" from the Arduino, and the same with the display when I press a button it prints "0" on the serial.

    I have probed the Rx pin on the F28379D controlcard, when I use Arduino I can see the "0" printed on the Rx pin which is normal because it works with Arduino but when I use the Display nothing appears on the probe just after connecting Tx display to the Rx of the DSP before connection I see the "0" printed but after connection No.

    Find attached the screens showing all these things."
    CS1034270.zip

    Kind regards,
    Gerald


  • Hi Gerald,

    Has the output of the level shifter been confirmed? Meaning is the data being sent by the F28379D being shifted correctly and vice versa? This is the only thing I can think of that would indicate an issue or difference between the F28379D and the display. Please check using a scope on both sides of the level shifter. Note that there needs to be one on both the TX and the RX lines. 

    Best Regards,

    Marlyn

  • Hi Marlyn,

    Thank you very much for your support and help it finally worked, the problem was about GPIO A Open Drain Output Register(GPAODR).
    Customer add this command to void config_SCIA() function:
    GPIO_setPadConfig(DEVICE_GPIO_PIN_SCIRXDA, GPIO_PIN_TYPE_OD);// pad config to open drain// 1:Open Drain Output/0:Normal Output/ GPAODR Register pg:985/spruhm8i.pdf

    Kind regards,
    Gerald