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