当前位置:   article > 正文

DSP TMS320F28335 SPI读写 flash W25X20_dsp28335外接flash

dsp28335外接flash

SPI IO初始化

  1. void
  2. InitSpiaGpio()
  3. {
  4. EALLOW;
  5. //
  6. // Enable internal pull-up for the selected pins
  7. // Pull-ups can be enabled or disabled by the user.
  8. // This will enable the pullups for the specified pins.
  9. // Comment out other unwanted lines.
  10. //
  11. GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0; //Enable pull-up on GPIO16 (SPISIMOA)
  12. GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; //Enable pull-up on GPIO17 (SPISOMIA)
  13. GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; //Enable pull-up on GPIO18 (SPICLKA)
  14. GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; //Enable pull-up on GPIO19 (SPISTEA)
  15. //GpioCtrlRegs.GPBPUD.bit.GPIO54 = 0; //Enable pull-up on GPIO54 (SPISIMOA)
  16. //GpioCtrlRegs.GPBPUD.bit.GPIO55 = 0; //Enable pull-up on GPIO55 (SPISOMIA)
  17. //GpioCtrlRegs.GPBPUD.bit.GPIO56 = 0; //Enable pull-up on GPIO56 (SPICLKA)
  18. //GpioCtrlRegs.GPBPUD.bit.GPIO57 = 0; //Enable pull-up on GPIO57 (SPISTEA)
  19. //
  20. // Set qualification for selected pins to asynch only
  21. // This will select asynch (no qualification) for the selected pins.
  22. // Comment out other unwanted lines.
  23. //
  24. // GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 0; // Asynch input GPIO16 (SPISIMOA)
  25. // GpioCtrlRegs.GPADIR.bit.GPIO17 = 0;
  26. GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (SPISIMOA)
  27. GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (SPISOMIA)
  28. GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO18 (SPICLKA)
  29. GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SPISTEA)
  30. //GpioCtrlRegs.GPBQSEL2.bit.GPIO54 = 3; // Asynch input GPIO16 (SPISIMOA)
  31. //GpioCtrlRegs.GPBQSEL2.bit.GPIO55 = 3; // Asynch input GPIO17 (SPISOMIA)
  32. //GpioCtrlRegs.GPBQSEL2.bit.GPIO56 = 3; // Asynch input GPIO18 (SPICLKA)
  33. //GpioCtrlRegs.GPBQSEL2.bit.GPIO57 = 3; // Asynch input GPIO19 (SPISTEA)
  34. //
  35. // Configure SPI-A pins using GPIO regs
  36. // This specifies which of the possible GPIO pins will be SPI
  37. // functional pins.
  38. // Comment out other unwanted lines.
  39. //
  40. GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA
  41. GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA
  42. GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as SPICLKA
  43. GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; // Configure GPIO19 as SPISTEA
  44. //GpioCtrlRegs.GPBMUX2.bit.GPIO54 = 1; // Configure GPIO54 as SPISIMOA
  45. //GpioCtrlRegs.GPBMUX2.bit.GPIO55 = 1; // Configure GPIO55 as SPISOMIA
  46. //GpioCtrlRegs.GPBMUX2.bit.GPIO56 = 1; // Configure GPIO56 as SPICLKA
  47. //GpioCtrlRegs.GPBMUX2.bit.GPIO57 = 1; // Configure GPIO57 as SPISTEA
  48. EDIS;
  49. }

初始化SPIA相关寄存器

  1. void InitSpia(void)
  2. {
  3. SpiaRegs.SPICCR.bit.SPISWRESET = 0; //SPI复位
  4. //数据在时钟上升沿发送,在时钟下降沿所存输入的数据
  5. SpiaRegs.SPICCR.bit.CLKPOLARITY = 0; //上升沿触发
  6. SpiaRegs.SPICTL.bit.CLK_PHASE = 1; //延时时钟
  7. SpiaRegs.SPICCR.bit.SPILBK = 0; //禁止内部回路
  8. SpiaRegs.SPICCR.bit.SPICHAR = 0xF; //发送和接收的数据长度16
  9. SpiaRegs.SPICTL.bit.OVERRUNINTENA = 0; //关闭溢出中断
  10. SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1; //主控制器模式
  11. SpiaRegs.SPICTL.bit.TALK = 1; //使能发送功能
  12. SpiaRegs.SPICTL.bit.SPIINTENA = 0; //禁止SPI中断
  13. SpiaRegs.SPIBRR = 0x63; //波特率=150M/4/100=375K
  14. SpiaRegs.SPIPRI.bit.FREE = 1; //仿真不影响发送数据
  15. SpiaRegs.SPICCR.bit.SPISWRESET = 1; //SPI功能恢复
  16. }

SPI 轮询发送与接受

  1. void spi_xmit(Uint16 a)
  2. {
  3. SpiaRegs.SPITXBUF=a;//左对齐
  4. while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG){}
  5. g_wData[0] = SpiaRegs.SPIRXBUF;
  6. while(SpiaRegs.SPIFFRX.bit.RXFFST != 0);
  7. SpiaRegs.SPITXBUF=0XFFFF;//左对齐
  8. while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG){}
  9. g_wData[1] = SpiaRegs.SPIRXBUF;
  10. while(SpiaRegs.SPIFFRX.bit.RXFFST != 0);
  11. SpiaRegs.SPITXBUF=0XFFFF;//左对齐
  12. while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG){}
  13. g_wData[2] = SpiaRegs.SPIRXBUF;
  14. while(SpiaRegs.SPIFFRX.bit.RXFFST != 0);
  15. SpiaRegs.SPITXBUF=0XFFFF;//左对齐
  16. while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG){}
  17. g_wData[3] = SpiaRegs.SPIRXBUF;
  18. while(SpiaRegs.SPIFFRX.bit.RXFFST != 0);
  19. SpiaRegs.SPITXBUF=0XFFFF;//左对齐
  20. while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG){}
  21. g_wData[4] = SpiaRegs.SPIRXBUF;
  22. while(SpiaRegs.SPIFFRX.bit.RXFFST != 0);
  23. SpiaRegs.SPITXBUF=0XFFFF;//左对齐
  24. while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG){}
  25. g_wData[5] = SpiaRegs.SPIRXBUF;
  26. while(SpiaRegs.SPIFFRX.bit.RXFFST != 0);
  27. //
  28. g_wData[6] = SpiaRegs.SPIRXBUF;
  29. while(SpiaRegs.SPIFFRX.bit.RXFFST != 0);
  30. }

波形(发送0x9f)查询JEDEC ID编码回复0xEF 0X3012

绿色:SPI_MOSI

黄色:SPI_CS

紫色:SPI_MISO

蓝色:SPI_CLK

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/704060
推荐阅读
相关标签
  

闽ICP备14008679号