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.

CCS/TMS320F28379D: scib scia

Part Number: TMS320F28379D

Tool/software: Code Composer Studio

hi, i have a problem with uart comunication.

im looking to do a code, where i can write and read from 2 pins.

with my code i read an input from scia(pin 42 43) and after i write the number in my array [1,2,3,4,5] on the serial monitor , when i have finish to write the sequence i write a word "d".

the only thing i want do now is use not scia pin (42 43)  but two other pins for examble with scia b. its many day i m looking for do this but with no results:(.
can you help me to change the code.? tyhanks

#include <math.h>
#include "F28x_Project.h"
#include <stdio.h>
Uint16 LoopCount=0;
Uint16 Received[100];

Uint16 vettore[5]={1,2,3,4,5};
Uint16 n=4;
int x=0;
Uint16 ReceivedChar;
Uint16 i=0;
int prova=1;
int fine=100;
float fvar=2.43;
union
{
float f;
char c[4];
} floatNchars;

float nx = 3.567;

void scia_echoback_init(void);
void scia_fifo_init(void);
void scia_xmit(int a);
void scia_msg(char *msg);
void scib_msg(char *msg);
void scib_xmit(int a);

void scia_rec (void);
void scia_float(int *f);
void ftoa(float n, char* res, int afterpoint);
void InitScibGpio() ;
void main(void)

{
InitSysPll(XTAL_OSC, IMULT_20, FMULT_0, PLLCLK_BY_2);
char *msg;

InitSysCtrl();
InitGpio();

GPIO_SetupPinMux(43, GPIO_MUX_CPU1, 0x0F);
GPIO_SetupPinOptions(43, GPIO_INPUT, GPIO_PUSHPULL);
GPIO_SetupPinMux(42, GPIO_MUX_CPU1, 0x0F);
GPIO_SetupPinOptions(42, GPIO_OUTPUT, GPIO_ASYNC);
GPIO_SetupPinMux (19 , GPIO_MUX_CPU1 , 2 ); // set pin 18 to MUX position 2 as UARTA RX
GPIO_SetupPinOptions(19 , GPIO_INPUT , GPIO_PUSHPULL); // set pin as RX
GPIO_SetupPinMux (18 , GPIO_MUX_CPU1 , 2 ); // set pin 19 to MUX position 2 as UARTA TX
GPIO_SetupPinOptions(18 , GPIO_OUTPUT , GPIO_ASYNC );
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();


scia_fifo_init(); // Initialize the SCI FIFO
scia_echoback_init(); // Initialize SCI for echoback

floatNchars.f = fvar;

scia_xmit(floatNchars.c[0]);
scia_xmit(floatNchars.c[1]);
scia_xmit(floatNchars.c[2]);
scia_xmit(floatNchars.c[3]);

msg = "\r\n invio vettore: \0";
scia_msg(msg);


__byte(&fine,1) = fine + '0';
for(LoopCount=0;LoopCount<2;LoopCount++) {

//

while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for empty state

scia_rec();

while(Received[i] != ' \n\0')
{

scia_xmit(Received[i]); i++; }

for(i=0;n>=i;i++)
{
__byte(&prova,0) = vettore[i]+ '0';

SciaRegs.SCITXBUF.all =prova;
ScibRegs.SCITXBUF.all =prova;
}
i=0;
if (i=n){SciaRegs.SCITXBUF.all =fine; }
DELAY_US(500000);

}
}


void scia_rec (void)
{
while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for empty state
Received[x] = SciaRegs.SCIRXBUF.all;
x++;
}
void scia_echoback_init()
{

SciaRegs.SCICCR.all = 0x0007; // 1 stop bit, No loopback
SciaRegs.SCICTL1.all = 0x0003; // enable TX, RX, internal SCICLK,
SciaRegs.SCICTL2.all = 0x0003;
SciaRegs.SCICTL2.bit.TXINTENA = 1;
SciaRegs.SCICTL2.bit.RXBKINTENA = 1;
SciaRegs.SCIHBAUD.all = 0x0002;
SciaRegs.SCILBAUD.all = 0x008B;

SciaRegs.SCICTL1.all = 0x0023; // Relinquish SCI from Reset

// SCIA at 9600 baud
// @LSPCLK = 50 MHz (200 MHz SYSCLK) HBAUD = 0x02 and LBAUD = 0x8B.
// @LSPCLK = 30 MHz (120 MHz SYSCLK) HBAUD = 0x01 and LBAUD = 0x86.
//

// Note: Clocks were turned on to the SCIB peripheral
// in the InitSysCtrl() function
//
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.all = 0x0003; //enable TX,RX interrupt
ScibRegs.SCICTL2.bit.TXINTENA = 1;
ScibRegs.SCICTL2.bit.RXBKINTENA = 1;
//
// SCIB at 9600 baud
// @LSPCLK = 50 MHz (200 MHz SYSCLK) HBAUD = 0x02 and LBAUD = 0x8B.
// @LSPCLK = 30 MHz (120 MHz SYSCLK) HBAUD = 0x01 and LBAUD = 0x86.
//
ScibRegs.SCIHBAUD.all = 0x0002;
ScibRegs.SCILBAUD.all = 0x008B;
ScibRegs.SCICTL1.all = 0x0023; // Relinquish SCI from Reset
}

void scia_xmit(int a)
{
while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
SciaRegs.SCITXBUF.all =a;

}
void scib_xmit(int a)
{


while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}
ScibRegs.SCITXBUF.all =a;

}
void scia_msg(char * msg)
{
int i;
i = 0;
while(msg[i]!='\0')
{scia_xmit(msg[i]); i++;}}
void scib_msg(char * msg)
{
int i;
i = 0;
while(msg[i]!='\0')
{scib_xmit(msg[i]); i++;}}
void scia_float(int *f)
{
int i;
i = 0;
while(f[i]!='\0')
{scia_xmit(f[i]); i++;}}


void scib_fifo_init(void)
{
ScibRegs.SCICCR.all = 0x0007;
ScibRegs.SCICTL1.all = 0x0003;
ScibRegs.SCIHBAUD.all = 0x0000;
// ScibRegs.SCILBAUD.all = SCI_PRD;
ScibRegs.SCIFFTX.all = 0xE040;
// ScibRegs.SCIFFRX.bit.RXFFIL = RXNUM;
ScibRegs.SCIFFRX.bit.RXFFINTCLR =1;
ScibRegs.SCIFFRX.bit.RXFIFORESET = 1;
}
/* echobach da inserire per prova
while(Received[i] != ' \n\0')
{
__byte(&prova,0) = vettore[i]+ '0';
scia_float(f);
ciaRegs.SCITXBUF.all =prova;
scia_xmit(Received[i]); i++; }
msg = " invio vettore \0";
scia_msg(msg);
scia_vet(vettore);
while(vettore[i] != '\0')
{ scia_xmit(vettore[i]); i++; }

*/
void InitScibGpio()
{
EALLOW;

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAPUD.bit.GPIO9 = 0; // Enable pull-up for GPIO9 (SCITXDB)
// GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0; // Enable pull-up for GPIO14 (SCITXDB)
GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; // Enable pull-up for GPIO18 (SCITXDB)
// GpioCtrlRegs.GPAPUD.bit.GPIO22 = 0; // Enable pull-up for GPIO22 (SCITXDB)


// GpioCtrlRegs.GPAPUD.bit.GPIO11 = 0; // Enable pull-up for GPIO11 (SCIRXDB)
// GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0; // Enable pull-up for GPIO15 (SCIRXDB)
GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; // Enable pull-up for GPIO19 (SCIRXDB)
// GpioCtrlRegs.GPAPUD.bit.GPIO23 = 0; // Enable pull-up for GPIO23 (SCIRXDB)

/* Set qualification for selected pins to asynch only */
// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAQSEL1.bit.GPIO11 = 3; // Asynch input GPIO11 (SCIRXDB)
// GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3; // Asynch input GPIO15 (SCIRXDB)
GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SCIRXDB)
// GpioCtrlRegs.GPAQSEL2.bit.GPIO23 = 3; // Asynch input GPIO23 (SCIRXDB)

/* Configure SCI-B pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be SCI functional pins.
// Comment out other unwanted lines.

// GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 2; // Configure GPIO9 for SCITXDB operation
// GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 2; // Configure GPIO14 for SCITXDB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 2; // Configure GPIO18 for SCITXDB operation
// GpioCtrlRegs.GPAMUX2.bit.GPIO22 = 3; // Configure GPIO22 for SCITXDB operation

// GpioCtrlRegs.GPAMUX1.bit.GPIO11 = 2; // Configure GPIO11 for SCIRXDB operation
// GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 2; // Configure GPIO15 for SCIRXDB operation
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 2; // Configure GPIO19 for SCIRXDB operation
// GpioCtrlRegs.GPAMUX2.bit.GPIO23 = 3; // Configure GPIO23 for SCIRXDB operation

EDIS;
}
void InitSciGpio()
{
InitSciaGpio();
#if DSP28_SCIB
InitScibGpio();
#endif // if DSP28_SCIB
}

void InitSciaGpio()
{
EALLOW;

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled disabled by the user.
// This will enable the pullups for the specified pins.

GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0; // Enable pull-up for GPIO28 (SCIRXDA)
GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0; // Enable pull-up for GPIO29 (SCITXDA)

/* Set qualification for selected pins to asynch only */
// Inputs are synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins.

GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3; // Asynch input GPIO28 (SCIRXDA)

/* Configure SCI-A pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be SCI functional pins.

GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 1; // Configure GPIO28 for SCIRXDA operation
GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 1; // Configure GPIO29 for SCITXDA operation

EDIS;
}
void scia_fifo_init()
{
SciaRegs.SCIFFTX.all = 0xE040;
SciaRegs.SCIFFRX.all = 0x2044;
SciaRegs.SCIFFCT.all = 0x0;}

  • Hi Leonardo,

    If you just want to use different pins, there are a variety of alternate bondouts for SCI-A.  You can see these in the datasheet in the table "GPIO Muxed Pins".

    To change the pins for SCI-A, you should just have to change the GPIO muxing code.

    If you want to change to SCI-B, you'll still need to change the GPIO muxing code, but also change all references of "SciaRegs" to "ScibRegs" and if you are using an ISR you'll also need to change where the ISR is mapped as well as what lines are enabled in the PIE.  

  • I have try to change my pin in my code but i dont know why they doesnt work:(...can you try to change my code...i need only 2 pins not connected with usb

    --

  • Hi Leonardo,

    In general we won't debug or edit your code directly.

    To configure the pin mux selection, two registers need to be written.  I'm not sure you are writing the second one?

    You can also run your GPIO mux setup code, then examine the GPIO configuration registers in the expressions window to see what was actually set.  This could help you find issues with your code not doing what you think it is doing.

  • Where i have to set these codes ? I dont have write these directly:(

  • Hi Leonardo,

    You can use the driverlib functions to configure the GPIOs if you don't want to directly write the registers.  This is actually how the example echoback code works:

    //
    // 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.
    //
    GPIO_SetupPinMux(28, GPIO_MUX_CPU1, 1);
    GPIO_SetupPinOptions(28, GPIO_INPUT, GPIO_PUSHPULL);
    GPIO_SetupPinMux(29, GPIO_MUX_CPU1, 1);
    GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC);

    If you want to directly write the registers, you need to write both the GPAMUX and the GPAGMUX registers to configure the GPIO (or GPBMUX or GPCMUX etc. registers, as appropriate).    

  • i have change my code with the new lines but the pins dont transmit nothing....i dont understand where the problem is:(

    #include <math.h>
    #include "F28x_Project.h"
    #include <stdio.h>
    Uint16 LoopCount=0;
    Uint16 Received[100];
    int vettore[5]={1,2,3,4,5};
    Uint16 n=4;
    int x=0;
    Uint16 ReceivedChar;
    Uint16 i=0;
    int prova=1;
    int fine=100;
    void scia_echoback_init(void);
    void scia_fifo_init(void);
    void scia_xmit(int a);
    void scia_msg(char *msg);

    void scia_rec (void);
    void scia_float(int *f);
    void ftoa(float n, char* res, int afterpoint);
    void main(void)

    { InitSysPll(XTAL_OSC, IMULT_20, FMULT_0, PLLCLK_BY_2);
    char *msg;

    InitSysCtrl();
    InitGpio();

    //GPIO_SetupPinMux(43, GPIO_MUX_CPU1, 0x0F);
    //GPIO_SetupPinOptions(43, GPIO_INPUT, GPIO_PUSHPULL);
    //GPIO_SetupPinMux(42, GPIO_MUX_CPU1, 0x0F);
    //GPIO_SetupPinOptions(42, GPIO_OUTPUT, GPIO_ASYNC);

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


    DINT;
    InitPieCtrl();
    IER = 0x0000;
    IFR = 0x0000;

    InitPieVectTable();


    scia_fifo_init(); // Initialize the SCI FIFO
    scia_echoback_init(); // Initialize SCI for echoback

    __byte(&fine,1) = fine + '0';
    for(LoopCount=0;LoopCount<1000;LoopCount++) {

    for(i=0;n>=i;i++)
    {
    __byte(&prova,0) = vettore[i]+ '0';

    SciaRegs.SCITXBUF.all =prova;

    }
    i=0;
    //if (i=n){SciaRegs.SCITXBUF.all =fine; }
    DELAY_US(500000);


    }
    }


    void scia_rec (void)
    {
    while(SciaRegs.SCIFFRX.bit.RXFFST == 0) { } // wait for empty state
    Received[x] = SciaRegs.SCIRXBUF.all;
    x++;
    }
    void scia_echoback_init()
    {

    SciaRegs.SCICCR.all = 0x0007; // 1 stop bit, No loopback
    SciaRegs.SCICTL1.all = 0x0003; // enable TX, RX, internal SCICLK,
    SciaRegs.SCICTL2.all = 0x0003;
    SciaRegs.SCICTL2.bit.TXINTENA = 1;
    SciaRegs.SCICTL2.bit.RXBKINTENA = 1;
    SciaRegs.SCIHBAUD.all = 0x0002;
    SciaRegs.SCILBAUD.all = 0x008B;

    SciaRegs.SCICTL1.all = 0x0023; // Relinquish SCI from Reset


    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.all = 0x0003; //enable TX,RX interrupt
    ScibRegs.SCICTL2.bit.TXINTENA = 1;
    ScibRegs.SCICTL2.bit.RXBKINTENA = 1;

    ScibRegs.SCIHBAUD.all = 0x0002;
    ScibRegs.SCILBAUD.all = 0x008B;
    ScibRegs.SCICTL1.all = 0x0023; // Relinquish SCI from Reset
    }

    void scia_xmit(int a)
    {
    while (SciaRegs.SCIFFTX.bit.TXFFST != 0) {}
    SciaRegs.SCITXBUF.all =a;

    while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}
    ScibRegs.SCITXBUF.all =a;

    }
    void scia_msg(char * msg)
    {
    int i;
    i = 0;
    while(msg[i]!='\0')
    {scia_xmit(msg[i]); i++;}}
    void scia_float(int *f)
    {
    int i;
    i = 0;
    while(f[i]!='\0')
    {scia_xmit(f[i]); i++;}}


    void scib_fifo_init(void)
    {
    ScibRegs.SCICCR.all = 0x0007;
    ScibRegs.SCICTL1.all = 0x0003;
    ScibRegs.SCIHBAUD.all = 0x0000;

    ScibRegs.SCIFFTX.all = 0xE040;

    ScibRegs.SCIFFRX.bit.RXFFINTCLR =1;
    ScibRegs.SCIFFRX.bit.RXFIFORESET = 1;
    }

    void scia_fifo_init()
    {
    SciaRegs.SCIFFTX.all = 0xE040;
    SciaRegs.SCIFFRX.all = 0x2044;
    SciaRegs.SCIFFCT.all = 0x0;}

  • Hi Leonardo,

    Keep iteratively reading the TRM and DS sections on GPIO, refer to the EVM schematics, trying the bitfield or driverlib examples, and trying to modify your example; you'll get it eventually.

    If you feel you are stuck on moving the SCI to a different set of pins, you may take a step back and try moving around a different peripheral (maybe ePWM) to further your understanding. 

    You might also try just toggling the target pins in question in GPIO output mode directly to verify that the hookup is correct.   

  • i dont have understand...what i have to try? arduino read all i send to him with other arduino or with pc, i think that the problem is on the Texas i....

    can you try to explane me what i can do?

    thanks for the help..

  • Hi Leonardo,

    If you want to change the mux option for SCI-A to another pin option for SCI-A:

    • Start with working SCI-A code on GPIO42 and GPIO43
    • Change the GPIOs
      • GPIO28 and GPIO29 are one option
      • Make sure you are mapping the old TX pin to the new TX pin (i.e. GPIO42 changed to GPIO29)
      • Mux position may not be the same between old and new (refer to the device datasheet)
      • e.g.
        • //GPIO_SetupPinMux(42, GPIO_MUX_CPU1, 0x0F);
          //GPIO_SetupPinOptions(42, GPIO_OUTPUT, GPIO_ASYNC);
          GPIO_SetupPinMux(29, GPIO_MUX_CPU1, 1);
          GPIO_SetupPinOptions(29, GPIO_OUTPUT, GPIO_ASYNC);
    • There should be no SCI-B related code necessary (i.e. ScibRegs.XXX)
    • You also need to physically move the transceiver connection from the old GPIOs to the new GPIOs

    If you want to change to SCI-B instead of SCI-A, then the process is similar, but you will have different GPIO options and you will need to replace any SCI-A code witih SCI-B code. 

  • The code work with scia pin(42 43) .when exchange the lines of code for pin 28 29 (you can see the code lines in the example upstair)instead doesnt sent nothing..

    What is transcriver connection?

    Thanks for the help

  • Hi Leonardo,

    The transceiver is whatever you are externally connecting to the SCI GPIOs.  This could be an RS-232 transceiver or something like an FTDI to USB translator.  

  • Ok in my case i have the usb when i use the pins 43 42 and arduino for 28 29 ...

  • somebody have a simple code that write something with 2 other pin instead of 42 43 and work well? i want try if my arduio read from this code somethings for understand if the promblems are in my code or in the connections ..

    thanks for the help

  • I have continued to make attempt but i dont have any results:(

    are there an example code where something is write using not pin 42-43, that work? I have looking every on the web but i have found only example with usb pin 42-43. All other example that i have found, also in this forum are not finished or doesnt work.

    Please help me and thanks for your help

    :(