TI中文支持网
TI专业的中文技术问题搜集分享网站

F28335的485通信问题

大家好,最近在调试28335的485通信,通过GPIO26控制ADM2582E芯片进行收发数据,DPIO26为高电平时发数,低电平时收数,采用Scib通道。在TI例程基础上修改如下:

#include "DSP28x_Project.h" // Device Headerfile and Examples Include File

void Scib_echoback_init(void);
void Scib_fifo_init(void);
void Scib_xmit(int a);
void Scib_msg(char *msg);
void delay(Uint16 count);
void Gpio_select(void);

Uint16 LoopCount;
Uint16 ErrorCount;

void main(void)
{
Uint16 ReceivedChar;
char *msg;

InitSysCtrl();

InitScibGpio();

DINT;

InitPieCtrl();

IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

LoopCount = 0;
ErrorCount = 0;

EALLOW;

GpioCtrlRegs.GPAPUD.bit.GPIO26= 0;
GpioCtrlRegs.GPAMUX2.bit.GPIO26= 0; 
GpioCtrlRegs.GPADIR.bit.GPIO26= 1;
GpioDataRegs.GPASET.bit.GPIO26= 1; 

EDIS;

Scib_fifo_init(); // Initialize the SCI FIFO
Scib_echoback_init(); // Initialize SCI for echoback

GpioDataRegs.GPASET.bit.GPIO26= 1;
delay(200);

delay(200);
msg = "\r\n\n\nHello World!\0";
Scib_msg(msg); 

msg = "\r\nYou will enter a character, and the DSP will echo it back! \n\0";
Scib_msg(msg); //TX

for(;;)
{
GpioDataRegs.GPASET.bit.GPIO26 = 1;
delay(200);

msg = "\r\nEnter a character: \0";
Scib_msg(msg);

GpioDataRegs.GPACLEAR.bit.GPIO26 = 1;
while(ScibRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for XRDY =1 for empty state

ReceivedChar = ScibRegs.SCIRXBUF.all;
GpioDataRegs.GPASET.bit.GPIO26 = 1;

msg = " You sent: \0";
Scib_msg(msg);
delay(200);
Scib_xmit(ReceivedChar); //RX
GpioDataRegs.GPASET.bit.GPIO26 = 1;
delay(200);
LoopCount++;
}
}

// Test 1,Scib DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity
void Scib_echoback_init()
{
// 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;
ScibRegs.SCICTL2.bit.TXINTENA =1;
ScibRegs.SCICTL2.bit.RXBKINTENA =1;
// #if (CPU_FRQ_150MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
ScibRegs.SCILBAUD =0x00E7;
// #endif

ScibRegs.SCIFFTX.all=0x801f;//0xe040;
ScibRegs.SCIFFRX.all=0x001f;
ScibRegs.SCIFFCT.all=0x00;

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

// Transmit a character from the SCI
void Scib_xmit(int a)
{
while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}
ScibRegs.SCITXBUF=a;
}

void Scib_msg(char * msg)
{
int i;
i = 0;
while(msg[i] != '\0')
{
Scib_xmit(msg[i]);
i++;
}
}

// Initialize the SCI FIFO
void Scib_fifo_init()
{
ScibRegs.SCIFFTX.all=0xE040;
ScibRegs.SCIFFRX.all=0x204f;
ScibRegs.SCIFFCT.all=0x0;
}

void delay(Uint16 count) /*count=1 about 0.1us */
{
while(count>0)
{
count–;
asm(" NOP");
asm(" NOP");
asm(" NOP");
asm(" NOP");
asm(" NOP");
asm(" NOP");
}
}

但是实现不了485通信功能,希望大家能帮忙找找原因,不胜感激。

Young Hu:先测测loopback能不能通,看一下链路上信号

大家好,最近在调试28335的485通信,通过GPIO26控制ADM2582E芯片进行收发数据,DPIO26为高电平时发数,低电平时收数,采用Scib通道。在TI例程基础上修改如下:

#include "DSP28x_Project.h" // Device Headerfile and Examples Include File

void Scib_echoback_init(void);
void Scib_fifo_init(void);
void Scib_xmit(int a);
void Scib_msg(char *msg);
void delay(Uint16 count);
void Gpio_select(void);

Uint16 LoopCount;
Uint16 ErrorCount;

void main(void)
{
Uint16 ReceivedChar;
char *msg;

InitSysCtrl();

InitScibGpio();

DINT;

InitPieCtrl();

IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

LoopCount = 0;
ErrorCount = 0;

EALLOW;

GpioCtrlRegs.GPAPUD.bit.GPIO26= 0;
GpioCtrlRegs.GPAMUX2.bit.GPIO26= 0; 
GpioCtrlRegs.GPADIR.bit.GPIO26= 1;
GpioDataRegs.GPASET.bit.GPIO26= 1; 

EDIS;

Scib_fifo_init(); // Initialize the SCI FIFO
Scib_echoback_init(); // Initialize SCI for echoback

GpioDataRegs.GPASET.bit.GPIO26= 1;
delay(200);

delay(200);
msg = "\r\n\n\nHello World!\0";
Scib_msg(msg); 

msg = "\r\nYou will enter a character, and the DSP will echo it back! \n\0";
Scib_msg(msg); //TX

for(;;)
{
GpioDataRegs.GPASET.bit.GPIO26 = 1;
delay(200);

msg = "\r\nEnter a character: \0";
Scib_msg(msg);

GpioDataRegs.GPACLEAR.bit.GPIO26 = 1;
while(ScibRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for XRDY =1 for empty state

ReceivedChar = ScibRegs.SCIRXBUF.all;
GpioDataRegs.GPASET.bit.GPIO26 = 1;

msg = " You sent: \0";
Scib_msg(msg);
delay(200);
Scib_xmit(ReceivedChar); //RX
GpioDataRegs.GPASET.bit.GPIO26 = 1;
delay(200);
LoopCount++;
}
}

// Test 1,Scib DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity
void Scib_echoback_init()
{
// 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;
ScibRegs.SCICTL2.bit.TXINTENA =1;
ScibRegs.SCICTL2.bit.RXBKINTENA =1;
// #if (CPU_FRQ_150MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
ScibRegs.SCILBAUD =0x00E7;
// #endif

ScibRegs.SCIFFTX.all=0x801f;//0xe040;
ScibRegs.SCIFFRX.all=0x001f;
ScibRegs.SCIFFCT.all=0x00;

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

// Transmit a character from the SCI
void Scib_xmit(int a)
{
while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}
ScibRegs.SCITXBUF=a;
}

void Scib_msg(char * msg)
{
int i;
i = 0;
while(msg[i] != '\0')
{
Scib_xmit(msg[i]);
i++;
}
}

// Initialize the SCI FIFO
void Scib_fifo_init()
{
ScibRegs.SCIFFTX.all=0xE040;
ScibRegs.SCIFFRX.all=0x204f;
ScibRegs.SCIFFCT.all=0x0;
}

void delay(Uint16 count) /*count=1 about 0.1us */
{
while(count>0)
{
count–;
asm(" NOP");
asm(" NOP");
asm(" NOP");
asm(" NOP");
asm(" NOP");
asm(" NOP");
}
}

但是实现不了485通信功能,希望大家能帮忙找找原因,不胜感激。

user4762646:

回复 Young Hu:

您好!按照您的建议采用了loopback进行测试,其中ReceivedChar是依次递增的,但仍然接收不到数据,代码如下:
#include "DSP28x_Project.h"// Device Headerfile and Examples Include File

// Prototype statements for functions found within this file.
void Scib_loopback_init(void);
void Scib_fifo_init(void);
void Scib_xmit(int a);
void error();
__interrupt void Scib_rx_isr(void);
__interrupt void Scib_tx_isr(void);
void delay(Uint16 count);
// Global counts used in this example
Uint16 LoopCount;
Uint16 ErrorCount;

void main(void)
{Uint16 SendChar;Uint16 ReceivedChar;

InitSysCtrl();

InitSciGpio();
DINT;IER = 0x0000;IFR = 0x0000;
InitPieVectTable();
EnableInterrupts();
LoopCount = 0;ErrorCount = 0;
Scib_fifo_init();// Initialize the SCI FIFOScib_loopback_init();// Initialize SCI for digital loop back
SendChar = 0;EALLOW;GpioCtrlRegs.GPAPUD.bit.GPIO26= 0;GpioCtrlRegs.GPAMUX2.bit.GPIO26= 0; GpioCtrlRegs.GPADIR.bit.GPIO26= 1; // outputGpioDataRegs.GPASET.bit.GPIO26= 1; // Load output latchEDIS;for(;;){Scib_xmit(SendChar);delay(100);GpioDataRegs.GPACLEAR.bit.GPIO26= 1;delay(100);while(ScibRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for RRDY/RXFFST =1 for 1 data available in FIFO
ReceivedChar = ScibRegs.SCIRXBUF.all;GpioDataRegs.GPASET.bit.GPIO26= 1;delay(100);if(ReceivedChar != SendChar) error();SendChar++;SendChar &= 0x00FF;LoopCount++;}
}

void error()
{ErrorCount++;
//__asm("ESTOP0");// Uncomment to stop the test here
//for (;;);
}

// Test 1,ScibDLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity
void Scib_loopback_init()
{// 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 protocolScibRegs.SCICTL1.all =0x0003;// enable TX, RX, internal SCICLK,// Disable RX ERR, SLEEP, TXWAKEScibRegs.SCICTL2.all =0x0003;ScibRegs.SCICTL2.bit.TXINTENA =1;ScibRegs.SCICTL2.bit.RXBKINTENA =1;ScibRegs.SCIHBAUD=0x0001;ScibRegs.SCILBAUD=0x00E7;ScibRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop backScibRegs.SCICTL1.all =0x0023;// Relinquish SCI from Reset
}

// Transmit a character from the SCI'
void Scib_xmit(int a)
{ScibRegs.SCITXBUF=a;
}

// Initialize the SCI FIFO
void Scib_fifo_init()
{ScibRegs.SCIFFTX.all=0xe040;ScibRegs.SCIFFRX.all=0x204f;ScibRegs.SCIFFCT.all=0x0;
}

void delay(Uint16 count)/*count=1 about 0.1us */
{while(count>0){count–;asm(" NOP");asm(" NOP");asm(" NOP");asm(" NOP");asm(" NOP");asm(" NOP");}
}
是不是SCIB和SCIA使用有区别呢?谢谢!

大家好,最近在调试28335的485通信,通过GPIO26控制ADM2582E芯片进行收发数据,DPIO26为高电平时发数,低电平时收数,采用Scib通道。在TI例程基础上修改如下:

#include "DSP28x_Project.h" // Device Headerfile and Examples Include File

void Scib_echoback_init(void);
void Scib_fifo_init(void);
void Scib_xmit(int a);
void Scib_msg(char *msg);
void delay(Uint16 count);
void Gpio_select(void);

Uint16 LoopCount;
Uint16 ErrorCount;

void main(void)
{
Uint16 ReceivedChar;
char *msg;

InitSysCtrl();

InitScibGpio();

DINT;

InitPieCtrl();

IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

LoopCount = 0;
ErrorCount = 0;

EALLOW;

GpioCtrlRegs.GPAPUD.bit.GPIO26= 0;
GpioCtrlRegs.GPAMUX2.bit.GPIO26= 0; 
GpioCtrlRegs.GPADIR.bit.GPIO26= 1;
GpioDataRegs.GPASET.bit.GPIO26= 1; 

EDIS;

Scib_fifo_init(); // Initialize the SCI FIFO
Scib_echoback_init(); // Initialize SCI for echoback

GpioDataRegs.GPASET.bit.GPIO26= 1;
delay(200);

delay(200);
msg = "\r\n\n\nHello World!\0";
Scib_msg(msg); 

msg = "\r\nYou will enter a character, and the DSP will echo it back! \n\0";
Scib_msg(msg); //TX

for(;;)
{
GpioDataRegs.GPASET.bit.GPIO26 = 1;
delay(200);

msg = "\r\nEnter a character: \0";
Scib_msg(msg);

GpioDataRegs.GPACLEAR.bit.GPIO26 = 1;
while(ScibRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for XRDY =1 for empty state

ReceivedChar = ScibRegs.SCIRXBUF.all;
GpioDataRegs.GPASET.bit.GPIO26 = 1;

msg = " You sent: \0";
Scib_msg(msg);
delay(200);
Scib_xmit(ReceivedChar); //RX
GpioDataRegs.GPASET.bit.GPIO26 = 1;
delay(200);
LoopCount++;
}
}

// Test 1,Scib DLB, 8-bit word, baud rate 0x000F, default, 1 STOP bit, no parity
void Scib_echoback_init()
{
// 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;
ScibRegs.SCICTL2.bit.TXINTENA =1;
ScibRegs.SCICTL2.bit.RXBKINTENA =1;
// #if (CPU_FRQ_150MHZ)
ScibRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
ScibRegs.SCILBAUD =0x00E7;
// #endif

ScibRegs.SCIFFTX.all=0x801f;//0xe040;
ScibRegs.SCIFFRX.all=0x001f;
ScibRegs.SCIFFCT.all=0x00;

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

// Transmit a character from the SCI
void Scib_xmit(int a)
{
while (ScibRegs.SCIFFTX.bit.TXFFST != 0) {}
ScibRegs.SCITXBUF=a;
}

void Scib_msg(char * msg)
{
int i;
i = 0;
while(msg[i] != '\0')
{
Scib_xmit(msg[i]);
i++;
}
}

// Initialize the SCI FIFO
void Scib_fifo_init()
{
ScibRegs.SCIFFTX.all=0xE040;
ScibRegs.SCIFFRX.all=0x204f;
ScibRegs.SCIFFCT.all=0x0;
}

void delay(Uint16 count) /*count=1 about 0.1us */
{
while(count>0)
{
count–;
asm(" NOP");
asm(" NOP");
asm(" NOP");
asm(" NOP");
asm(" NOP");
asm(" NOP");
}
}

但是实现不了485通信功能,希望大家能帮忙找找原因,不胜感激。

mangui zhang:对28335来讲其实就是SCI接口啊你先将485端收发短接看看自发自收有没有问题
如果还有问题你看看总线上的数量是否全双工等

赞(0)
未经允许不得转载:TI中文支持网 » F28335的485通信问题
分享到: 更多 (0)