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;}

