3902|2

9

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

关于scia_loopback_interrupt中断问题 [复制链接]

我是新手,在看scia_loopback_interrupt例程,不应该是先把要发送的数据写到SCITXBUF里,才会触发中断吗,为什么SciaRegs.SCITXBUF=sdataA[i];这个就在中断里,那他是如何进入中断的,求各位大神指教,困扰好久了
点赞 关注
 

回复
举报

9

帖子

0

TA的资源

一粒金砂(初级)

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

  2. #define CPU_FREQ          150E6
  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 sciaTxFifoIsr(void);
  8. interrupt void sciaRxFifoIsr(void);
  9. interrupt void scibTxFifoIsr(void);
  10. interrupt void scibRxFifoIsr(void);
  11. void scia_fifo_init(void);
  12. void scib_fifo_init(void);
  13. void error(void);

  14. // Global variables
  15. Uint16 sdataA[8];    // Send data for SCI-A
  16. Uint16 sdataB[8];    // Send data for SCI-B
  17. Uint16 rdataA[8];    // Received data for SCI-A
  18. Uint16 rdataB[8];    // Received data for SCI-A
  19. Uint16 rdata_pointA; // Used for checking the received data
  20. Uint16 rdata_pointB;


  21. void main(void)
  22. {
  23.    Uint16 i;

  24. // Step 1. Initialize System Control:
  25. // PLL, WatchDog, enable Peripheral Clocks
  26. // This example function is found in the DSP2833x_SysCtrl.c file.
  27.    InitSysCtrl();

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

  35. // Step 3. Clear all interrupts and initialize PIE vector table:
  36. // Disable CPU interrupts
  37.    DINT;

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

  43. // Disable CPU interrupts and clear all CPU interrupt flags:
  44.    IER = 0x0000;
  45.    IFR = 0x0000;

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

  53. // Interrupts that are used in this example are re-mapped to
  54. // ISR functions found within this file.
  55.    EALLOW;        // This is needed to write to EALLOW protected registers
  56.    PieVectTable.SCIRXINTA = &sciaRxFifoIsr;
  57.    PieVectTable.SCITXINTA = &sciaTxFifoIsr;
  58.    PieVectTable.SCIRXINTB = &scibRxFifoIsr;
  59.    PieVectTable.SCITXINTB = &scibTxFifoIsr;
  60.    EDIS;   // This is needed to disable write to EALLOW protected registers


  61. // Step 4. Initialize all the Device Peripherals:
  62. // This function is found in DSP2833x_InitPeripherals.c
  63. // InitPeripherals(); // Not required for this example
  64.    scia_fifo_init();  // Init SCI-A
  65.    scib_fifo_init();  // Init SCI-B

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

  67. // Init send data.  After each transmission this data
  68. // will be updated for the next transmission
  69.    for(i = 0; i<8; i++)
  70.    {
  71.       sdataA[i] = i;
  72.    }

  73.    for(i = 0; i<8; i++)
  74.    {
  75.       sdataB[i] = 0xFF - i;
  76.    }

  77.    rdata_pointA = sdataA[0];
  78.    rdata_pointB = sdataB[0];

  79. // Enable interrupts required for this example
  80.    PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
  81.    PieCtrlRegs.PIEIER9.bit.INTx1=1;     // PIE Group 9, int1
  82.    PieCtrlRegs.PIEIER9.bit.INTx2=1;     // PIE Group 9, INT2
  83.    PieCtrlRegs.PIEIER9.bit.INTx3=1;     // PIE Group 9, INT3
  84.    PieCtrlRegs.PIEIER9.bit.INTx4=1;     // PIE Group 9, INT4
  85.    IER = 0x100;        // Enable CPU INT
  86.    EINT;

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

  89. }

  90. void error(void)
  91. {
  92.     asm("     ESTOP0"); // Test failed!! Stop!
  93.     for (;;);
  94. }


  95. interrupt void sciaTxFifoIsr(void)
  96. {
  97.     Uint16 i;
  98.     for(i=0; i< 8; i++)
  99.     {
  100.            SciaRegs.SCITXBUF=sdataA[i];     // Send data
  101.         }

  102.     /*for(i=0; i< 8; i++)                 //Increment send data for next cycle
  103.     {
  104.            sdataA[i] = (sdataA[i]+1) & 0x00FF;
  105.         }*/

  106.         SciaRegs.SCIFFTX.bit.TXFFINTCLR=1;        // Clear SCI Interrupt flag
  107.         PieCtrlRegs.PIEACK.all|=0x100;      // Issue PIE ACK
  108. }

  109. interrupt void sciaRxFifoIsr(void)
  110. {
  111.     Uint16 i;
  112.         for(i=0;i<8;i++)
  113.         {
  114.            rdataA[i]=SciaRegs.SCIRXBUF.all;         // Read data
  115.         }
  116.         /*for(i=0;i<8;i++)                     // Check received data
  117.         {
  118.            if(rdataA[i] != ( (rdata_pointA+i) & 0x00FF) ) error();
  119.         }
  120.         rdata_pointA = (rdata_pointA+1) & 0x00FF;*/

  121.         SciaRegs.SCIFFRX.bit.RXFFOVRCLR=1;   // Clear Overflow flag
  122.         SciaRegs.SCIFFRX.bit.RXFFINTCLR=1;   // Clear Interrupt flag

  123.         PieCtrlRegs.PIEACK.all|=0x100;       // Issue PIE ack
  124. }

  125. void scia_fifo_init()
  126. {
  127.    SciaRegs.SCICCR.all =0x0007;   // 1 stop bit,  No loopback
  128.                                   // No parity,8 char bits,
  129.                                   // async mode, idle-line protocol
  130.    SciaRegs.SCICTL1.all =0x0003;  // enable TX, RX, internal SCICLK,
  131.                                   // Disable RX ERR, SLEEP, TXWAKE
  132.    SciaRegs.SCICTL2.bit.TXINTENA =1;
  133.    SciaRegs.SCICTL2.bit.RXBKINTENA =1;
  134.    SciaRegs.SCIHBAUD = 0x0000;
  135.    SciaRegs.SCILBAUD = SCI_PRD;
  136.    SciaRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back
  137.    SciaRegs.SCIFFTX.all=0xC028;
  138.    SciaRegs.SCIFFRX.all=0x0028;
  139.    SciaRegs.SCIFFCT.all=0x00;

  140.    SciaRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset
  141.    SciaRegs.SCIFFTX.bit.TXFIFOXRESET=1;
  142.    SciaRegs.SCIFFRX.bit.RXFIFORESET=1;


  143. }

  144. interrupt void scibTxFifoIsr(void)
  145. {
  146.     Uint16 i;
  147.     for(i=0; i< 8; i++)
  148.     {
  149.            ScibRegs.SCITXBUF=sdataB[i];     // Send data
  150.         }

  151.     for(i=0; i< 8; i++)                 //Increment send data for next cycle
  152.     {
  153.            sdataB[i] = (sdataB[i]-1) & 0x00FF;
  154.         }

  155.         ScibRegs.SCIFFTX.bit.TXFFINTCLR=1;  // Clear Interrupt flag
  156.         PieCtrlRegs.PIEACK.all|=0x100;      // Issue PIE ACK
  157. }

  158. interrupt void scibRxFifoIsr(void)
  159. {
  160.     Uint16 i;
  161.         for(i=0;i<8;i++)
  162.         {
  163.            rdataB[i]=ScibRegs.SCIRXBUF.all;         // Read data
  164.         }
  165.         for(i=0;i<8;i++)                     // Check received data
  166.         {
  167.            if(rdataB[i] != ( (rdata_pointB-i) & 0x00FF) ) error();
  168.         }
  169.         rdata_pointB = (rdata_pointB-1) & 0x00FF;

  170.         ScibRegs.SCIFFRX.bit.RXFFOVRCLR=1;  // Clear Overflow flag
  171.         ScibRegs.SCIFFRX.bit.RXFFINTCLR=1;         // Clear Interrupt flag
  172.         PieCtrlRegs.PIEACK.all|=0x100;          // Issue PIE ack
  173. }

  174. void scib_fifo_init()
  175. {
  176.    ScibRegs.SCICCR.all =0x0007;    // 1 stop bit,  No loopback
  177.                                    // No parity,8 char bits,
  178.                                    // async mode, idle-line protocol
  179.    ScibRegs.SCICTL1.all =0x0003;   // enable TX, RX, internal SCICLK,
  180.                                    // Disable RX ERR, SLEEP, TXWAKE
  181.    ScibRegs.SCICTL2.bit.TXINTENA =1;
  182.    ScibRegs.SCICTL2.bit.RXBKINTENA =1;
  183.    ScibRegs.SCIHBAUD    =0x0000;
  184.    ScibRegs.SCILBAUD    =SCI_PRD;
  185.    ScibRegs.SCICCR.bit.LOOPBKENA =1; // Enable loop back
  186.    ScibRegs.SCIFFTX.all=0xC028;
  187.    ScibRegs.SCIFFRX.all=0x0028;
  188.    ScibRegs.SCIFFCT.all=0x00;

  189.    ScibRegs.SCICTL1.all =0x0023;     // Relinquish SCI from Reset
  190.    ScibRegs.SCIFFTX.bit.TXFIFOXRESET=1;
  191.    ScibRegs.SCIFFRX.bit.RXFIFORESET=1;

  192. }

  193. //===========================================================================
  194. // No more.
  195. //===========================================================================
复制代码

这是例程 看到有人说通过TXRDY标志位引发中断,但是给SCIRXBUF和SCITXBUF赋值都是在中断里啊,那第一次是怎么进入中断的呢   求大神解答
 
 

回复

9

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
讨论讨论
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/7 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表