我自己改的dsp28335向下位机发送数据的程序,求大神帮看看...
时间:10-02
整理:3721RD
点击:
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#define SCI 1
#define UART_INT 0
interrupt void scibTxFifoIsr(void);
void scib_fifo_init();
void error(void);
Uint16 sdataB[6]={0x03,0x06,0x00,0x00,0x04,0x7F};
void main(void)
{
Uint16 i;
InitSysCtrl();
InitGpio();
InitSciGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.SCITXINTB = &scibTxFifoIsr;
EDIS;
scib_fifo_init();
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER9.bit.INTx3=1;
PieCtrlRegs.PIEIER9.bit.INTx4=1;
IFR = 0x0000;
IER = 0x100;
EINT;
for(;;);
}
interrupt void scibTxFifoIsr(void)
{
Uint16 i;
for(i=0;i<6;i++)
{
ScibRegs.SCITXBUF=sdataB[i];
}
ScibRegs.SCIFFTX.bit.TXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all|=0x100;
}
void scib_fifo_init()
{
ScibRegs.SCICCR.all =0x0007;
ScibRegs.SCICTL1.all =0x0003;
ScibRegs.SCICTL2.bit.TXINTENA =1;
ScibRegs.SCIHBAUD =0x001e;
ScibRegs.SCICCR.bit.LOOPBKENA =0;
ScibRegs.SCIFFTX.all=0xC020;
ScibRegs.SCIFFCT.all=0x00;
ScibRegs.SCICTL1.all =0x0023;
ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1;
ScibRegs.SCIFFRX.bit.RXFIFORESET=1;
}
void error(void)
{
asm(" ESTOP0"); // Test failed! Stop!
for (;;);
}
//===========================================================================
// No more.
//===========================================================================
这是我自己改的,应该有很多错误,各位大神别笑话我,我是新手,帮我看下吧,我想用dsp的sci实现和下位机的modbus通信,下位机是变频器,rs485接口,只要把数据发送过去,下位机能接到就可以,没有校验位,不需要返回,单向的发送就行,求高手指点!谢谢了!
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#define SCI 1
#define UART_INT 0
interrupt void scibTxFifoIsr(void);
void scib_fifo_init();
void error(void);
Uint16 sdataB[6]={0x03,0x06,0x00,0x00,0x04,0x7F};
void main(void)
{
Uint16 i;
InitSysCtrl();
InitGpio();
InitSciGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.SCITXINTB = &scibTxFifoIsr;
EDIS;
scib_fifo_init();
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
PieCtrlRegs.PIEIER9.bit.INTx3=1;
PieCtrlRegs.PIEIER9.bit.INTx4=1;
IFR = 0x0000;
IER = 0x100;
EINT;
for(;;);
}
interrupt void scibTxFifoIsr(void)
{
Uint16 i;
for(i=0;i<6;i++)
{
ScibRegs.SCITXBUF=sdataB[i];
}
ScibRegs.SCIFFTX.bit.TXFFINTCLR=1; // Clear Interrupt flag
PieCtrlRegs.PIEACK.all|=0x100;
}
void scib_fifo_init()
{
ScibRegs.SCICCR.all =0x0007;
ScibRegs.SCICTL1.all =0x0003;
ScibRegs.SCICTL2.bit.TXINTENA =1;
ScibRegs.SCIHBAUD =0x001e;
ScibRegs.SCICCR.bit.LOOPBKENA =0;
ScibRegs.SCIFFTX.all=0xC020;
ScibRegs.SCIFFCT.all=0x00;
ScibRegs.SCICTL1.all =0x0023;
ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1;
ScibRegs.SCIFFRX.bit.RXFIFORESET=1;
}
void error(void)
{
asm(" ESTOP0"); // Test failed! Stop!
for (;;);
}
//===========================================================================
// No more.
//===========================================================================
这是我自己改的,应该有很多错误,各位大神别笑话我,我是新手,帮我看下吧,我想用dsp的sci实现和下位机的modbus通信,下位机是变频器,rs485接口,只要把数据发送过去,下位机能接到就可以,没有校验位,不需要返回,单向的发送就行,求高手指点!谢谢了!
大神们给给回复呀 我试了一下 怎么这个程序无限发送数据啊 根本停不下来 怎么回事!
怎么让它发送完 就停止发送呢 求指导呀
- #include "DSP28x_Project.h" // Device Headerfile and Examples Include File
- #define CPU_FREQ 90E6
- #define LSPCLK_FREQ CPU_FREQ/4
- #define SCI_FREQ 100E3
- #define SCI_PRD (LSPCLK_FREQ/(SCI_FREQ*8))-1
- // Prototype statements for functions found within this file.
- __interrupt void ScibTxFifoIsr(void);
- __interrupt void ScibRxFifoIsr(void);
- __interrupt void ScibTxFifoIsr(void);
- __interrupt void ScibRxFifoIsr(void);
- void Scib_fifo_init(void);
- void Scib_fifo_init(void);
- void error(void);
- // Global variables
- Uint16 sdataA[2]; // Send data for SCI-A
- Uint16 rdataA[2]; // Received data for SCI-A
- Uint16 rdata_pointA; // Used for checking the received data
- void main(void)
- {
- Uint16 i;
- // Step 1. Initialize System Control:
- // PLL, WatchDog, enable Peripheral Clocks
- // This example function is found in the F2806x_SysCtrl.c file.
- InitSysCtrl();
- // Step 2. Initalize GPIO:
- // This example function is found in the F2806x_Gpio.c file and
- // illustrates how to set the GPIO to it's default state.
- // InitGpio();
- // Setup only the GP I/O only for SCI-A and SCI-B functionality
- // This function is found in F2806x_Sci.c
- InitSciGpio();
- // Step 3. Clear all interrupts and initialize PIE vector table:
- // Disable CPU interrupts
- DINT;
- // Initialize PIE control registers to their default state.
- // The default state is all PIE interrupts disabled and flags
- // are cleared.
- // This function is found in the F2806x_PieCtrl.c file.
- InitPieCtrl();
- // Disable CPU interrupts and clear all CPU interrupt flags:
- IER = 0x0000;
- IFR = 0x0000;
- // Initialize the PIE vector table with pointers to the shell Interrupt
- // Service Routines (ISR).
- // This will populate the entire table, even if the interrupt
- // is not used in this example. This is useful for debug purposes.
- // The shell ISR routines are found in F2806x_DefaultIsr.c.
- // This function is found in F2806x_PieVect.c.
- InitPieVectTable();
- // Interrupts that are used in this example are re-mapped to
- // ISR functions found within this file.
- EALLOW; // This is needed to write to EALLOW protected registers
- PieVectTable.SCIRXINTB = &ScibRxFifoIsr;
- PieVectTable.SCITXINTB = &ScibTxFifoIsr;
- EDIS; // This is needed to disable write to EALLOW protected registers
- // Step 4. Initialize all the Device Peripherals:
- // This function is found in F2806x_InitPeripherals.c
- // InitPeripherals(); // Not required for this example
- Scib_fifo_init(); // Init SCI-A
- // Step 5. User specific code, enable interrupts:
- // Init send data. After each transmission this data
- // will be updated for the next transmission
- for(i = 0; i<2; i++)
- {
- sdataA[i] = i;
- }
- rdata_pointA = sdataA[0];
- // Enable interrupts required for this example
- PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
- PieCtrlRegs.PIEIER9.bit.INTx1=1; // PIE Group 9, INT1
- PieCtrlRegs.PIEIER9.bit.INTx2=1; // PIE Group 9, INT2
- IER = 0x100; // Enable CPU INT
- EINT;
- // Step 6. IDLE loop. Just sit and loop forever (optional):
- for(;;);
- }
- void error(void)
- {
- __asm(" ESTOP0"); // Test failed! Stop!
- for (;;);
- }
- __interrupt void ScibTxFifoIsr(void)
- {
- Uint16 i;
- for(i=0; i< 2; i++)
- {
- ScibRegs.SCITXBUF=sdataA[i]; // Send data
- }
- for(i=0; i< 2; i++) //Increment send data for next cycle
- {
- sdataA[i] = (sdataA[i]+1) & 0x00FF;
- }
- ScibRegs.SCIFFTX.bit.TXFFINTCLR=1; // Clear SCI Interrupt flag
- PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ACK
- }
- __interrupt void ScibRxFifoIsr(void)
- {
- Uint16 i;
- for(i=0;i<2;i++)
- {
- rdataA[i]=ScibRegs.SCIRXBUF.all; // Read data
- }
- for(i=0;i<2;i++) // Check received data
- {
- if(rdataA[i] != ( (rdata_pointA+i) & 0x00FF) ) error();
- }
- rdata_pointA = (rdata_pointA+1) & 0x00FF;
- ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1; // Clear Overflow flag
- ScibRegs.SCIFFRX.bit.RXFFINTCLR=1; // Clear Interrupt flag
- PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ack
- }
- void Scib_fifo_init()
- {
- 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.bit.TXINTENA =1;
- ScibRegs.SCICTL2.bit.RXBKINTENA =1;
- ScibRegs.SCIHBAUD = 0x0000;
- ScibRegs.SCILBAUD = SCI_PRD;
- ScibRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back
- ScibRegs.SCIFFTX.all=0xC022;
- ScibRegs.SCIFFRX.all=0x0022;
- ScibRegs.SCIFFCT.all=0x00;
- ScibRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
- ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1;
- ScibRegs.SCIFFRX.bit.RXFIFORESET=1;
- }
- //===========================================================================
- // No more.
- //===========================================================================
加一个标志位试试
我觉也是应该加个标志位或是停止标志
做个定时器嘛,按时间发送,定时10ms,20ms自己控制哈,发送完成以后可以将发送使能清零
正在学习28335,谢谢小编分享,,,,,
学习了一些东东