我自己改的dsp28335向下位机发送数据的程序,求大神帮看看...

2019-07-15 18:31发布

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

    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接口,只要把数据发送过去,下位机能接到就可以,没有校验位,不需要返回,单向的发送就行,求高手指点!!!谢谢了!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
9条回答
z00
2019-07-16 02:59

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

  2. #define CPU_FREQ    90E6
  3. #define LSPCLK_FREQ CPU_FREQ/4
  4. #define SCI_FREQ    100E3
  5. #define SCI_PRD     (LSPCLK_FREQ/(SCI_FREQ*8))-1

  6. // Prototype statements for functions found within this file.
  7. __interrupt void ScibTxFifoIsr(void);
  8. __interrupt void ScibRxFifoIsr(void);
  9. __interrupt void ScibTxFifoIsr(void);
  10. __interrupt void ScibRxFifoIsr(void);
  11. void Scib_fifo_init(void);
  12. void Scib_fifo_init(void);
  13. void error(void);

  14. // Global variables
  15. Uint16 sdataA[2];    // Send data for SCI-A
  16. Uint16 rdataA[2];    // Received data for SCI-A
  17. Uint16 rdata_pointA; // Used for checking the received data

  18. void main(void)
  19. {
  20.    Uint16 i;

  21. // Step 1. Initialize System Control:
  22. // PLL, WatchDog, enable Peripheral Clocks
  23. // This example function is found in the F2806x_SysCtrl.c file.
  24.    InitSysCtrl();

  25. // Step 2. Initalize GPIO:
  26. // This example function is found in the F2806x_Gpio.c file and
  27. // illustrates how to set the GPIO to it's default state.
  28. // InitGpio();
  29. // Setup only the GP I/O only for SCI-A and SCI-B functionality
  30. // This function is found in F2806x_Sci.c
  31.    InitSciGpio();

  32. // Step 3. Clear all interrupts and initialize PIE vector table:
  33. // Disable CPU interrupts
  34.    DINT;

  35. // Initialize PIE control registers to their default state.
  36. // The default state is all PIE interrupts disabled and flags
  37. // are cleared.
  38. // This function is found in the F2806x_PieCtrl.c file.
  39.    InitPieCtrl();

  40. // Disable CPU interrupts and clear all CPU interrupt flags:
  41.    IER = 0x0000;
  42.    IFR = 0x0000;

  43. // Initialize the PIE vector table with pointers to the shell Interrupt
  44. // Service Routines (ISR).
  45. // This will populate the entire table, even if the interrupt
  46. // is not used in this example.  This is useful for debug purposes.
  47. // The shell ISR routines are found in F2806x_DefaultIsr.c.
  48. // This function is found in F2806x_PieVect.c.
  49.    InitPieVectTable();

  50. // Interrupts that are used in this example are re-mapped to
  51. // ISR functions found within this file.
  52.    EALLOW;  // This is needed to write to EALLOW protected registers
  53.    PieVectTable.SCIRXINTB = &ScibRxFifoIsr;
  54.    PieVectTable.SCITXINTB = &ScibTxFifoIsr;
  55.    EDIS;   // This is needed to disable write to EALLOW protected registers

  56. // Step 4. Initialize all the Device Peripherals:
  57. // This function is found in F2806x_InitPeripherals.c
  58. // InitPeripherals(); // Not required for this example
  59.    Scib_fifo_init();  // Init SCI-A

  60. // Step 5. User specific code, enable interrupts:

  61. // Init send data.  After each transmission this data
  62. // will be updated for the next transmission
  63.    for(i = 0; i<2; i++)
  64.    {
  65.       sdataA[i] = i;
  66.    }

  67.    rdata_pointA = sdataA[0];
  68. // Enable interrupts required for this example
  69.    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
  70.    PieCtrlRegs.PIEIER9.bit.INTx1=1;     // PIE Group 9, INT1
  71.    PieCtrlRegs.PIEIER9.bit.INTx2=1;     // PIE Group 9, INT2
  72.    IER = 0x100; // Enable CPU INT
  73.    EINT;

  74. // Step 6. IDLE loop. Just sit and loop forever (optional):
  75.     for(;;);

  76. }

  77. void error(void)
  78. {
  79.    __asm("     ESTOP0"); // Test failed!! Stop!
  80.     for (;;);
  81. }

  82. __interrupt void ScibTxFifoIsr(void)
  83. {
  84.     Uint16 i;
  85.     for(i=0; i< 2; i++)
  86.     {
  87.        ScibRegs.SCITXBUF=sdataA[i];     // Send data
  88.     }

  89.     for(i=0; i< 2; i++)                 //Increment send data for next cycle
  90.     {
  91.        sdataA[i] = (sdataA[i]+1) & 0x00FF;
  92.     }

  93.     ScibRegs.SCIFFTX.bit.TXFFINTCLR=1;  // Clear SCI Interrupt flag
  94.     PieCtrlRegs.PIEACK.all|=0x100;      // Issue PIE ACK
  95. }

  96. __interrupt void ScibRxFifoIsr(void)
  97. {
  98.     Uint16 i;
  99.     for(i=0;i<2;i++)
  100.     {
  101.        rdataA[i]=ScibRegs.SCIRXBUF.all;  // Read data
  102.     }
  103.     for(i=0;i<2;i++)                     // Check received data
  104.     {
  105.        if(rdataA[i] != ( (rdata_pointA+i) & 0x00FF) ) error();
  106.     }
  107.     rdata_pointA = (rdata_pointA+1) & 0x00FF;

  108.     ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1;   // Clear Overflow flag
  109.     ScibRegs.SCIFFRX.bit.RXFFINTCLR=1;   // Clear Interrupt flag

  110.     PieCtrlRegs.PIEACK.all|=0x100;       // Issue PIE ack
  111. }

  112. void Scib_fifo_init()
  113. {
  114.    ScibRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback
  115.                                   // No parity,8 char bits,
  116.                                   // async mode, idle-line protocol
  117.    ScibRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK,
  118.                                   // Disable RX ERR, SLEEP, TXWAKE
  119.    ScibRegs.SCICTL2.bit.TXINTENA =1;
  120.    ScibRegs.SCICTL2.bit.RXBKINTENA =1;
  121.    ScibRegs.SCIHBAUD = 0x0000;
  122.    ScibRegs.SCILBAUD = SCI_PRD;
  123.    ScibRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back
  124.    ScibRegs.SCIFFTX.all=0xC022;
  125.    ScibRegs.SCIFFRX.all=0x0022;
  126.    ScibRegs.SCIFFCT.all=0x00;

  127.    ScibRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset
  128.    ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1;
  129.    ScibRegs.SCIFFRX.bit.RXFIFORESET=1;

  130. }

  131. //===========================================================================
  132. // No more.
  133. //===========================================================================
复制代码

一周热门 更多>