DSP2803x_Spi.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //###########################################################################
  2. //
  3. // FILE: DSP2803x_Spi.c
  4. //
  5. // TITLE: DSP2803x SPI Initialization & Support Functions.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2803x C/C++ Header Files and Peripheral Examples V130 $
  9. // $Release Date: May 8, 2015 $
  10. // $Copyright: Copyright (C) 2009-2015 Texas Instruments Incorporated -
  11. // http://www.ti.com/ ALL RIGHTS RESERVED $
  12. //###########################################################################
  13. #include "DSP2803x_Device.h" // DSP2803x Headerfile Include File
  14. #include "DSP2803x_Examples.h" // DSP2803x Examples Include File
  15. //---------------------------------------------------------------------------
  16. // InitSPI:
  17. //---------------------------------------------------------------------------
  18. // This function initializes the SPI(s) to a known state.
  19. //
  20. void InitSpi(void)
  21. {
  22. // Initialize SPI-A
  23. //tbd...
  24. }
  25. //---------------------------------------------------------------------------
  26. // Example: InitSpiGpio:
  27. //---------------------------------------------------------------------------
  28. // This function initializes GPIO pins to function as SPI pins
  29. //
  30. // Each GPIO pin can be configured as a GPIO pin or up to 3 different
  31. // peripheral functional pins. By default all pins come up as GPIO
  32. // inputs after reset.
  33. //
  34. // Caution:
  35. // For each SPI peripheral
  36. // Only one GPIO pin should be enabled for SPISOMO operation.
  37. // Only one GPIO pin should be enabled for SPISOMI operation.
  38. // Only one GPIO pin should be enabled for SPICLK operation.
  39. // Only one GPIO pin should be enabled for SPISTE operation.
  40. // Comment out other unwanted lines.
  41. void InitSpiGpio()
  42. {
  43. InitSpiaGpio();
  44. #if DSP28_SPIB
  45. InitSpibGpio();
  46. #endif // endif DSP28_SPIB
  47. }
  48. void InitSpiaGpio()
  49. {
  50. EALLOW;
  51. /* Enable internal pull-up for the selected pins */
  52. // Pull-ups can be enabled or disabled by the user.
  53. // This will enable the pullups for the specified pins.
  54. // Comment out other unwanted lines.
  55. GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0; // Enable pull-up on GPIO16 (SPISIMOA)
  56. // GpioCtrlRegs.GPAPUD.bit.GPIO5 = 0; // Enable pull-up on GPIO5 (SPISIMOA)
  57. GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0; // Enable pull-up on GPIO17 (SPISOMIA)
  58. // GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0; // Enable pull-up on GPIO3 (SPISOMIA)
  59. GpioCtrlRegs.GPAPUD.bit.GPIO18 = 0; // Enable pull-up on GPIO18 (SPICLKA)
  60. GpioCtrlRegs.GPAPUD.bit.GPIO19 = 0; // Enable pull-up on GPIO19 (SPISTEA)
  61. /* Set qualification for selected pins to asynch only */
  62. // This will select asynch (no qualification) for the selected pins.
  63. // Comment out other unwanted lines.
  64. GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (SPISIMOA)
  65. // GpioCtrlRegs.GPAQSEL1.bit.GPIO5 = 3; // Asynch input GPIO5 (SPISIMOA)
  66. GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (SPISOMIA)
  67. // GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 3; // Asynch input GPIO3 (SPISOMIA)
  68. GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO18 (SPICLKA)
  69. GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SPISTEA)
  70. /* Configure SPI-A pins using GPIO regs*/
  71. // This specifies which of the possible GPIO pins will be SPI functional pins.
  72. // Comment out other unwanted lines.
  73. GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA
  74. // GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 2; // Configure GPIO5 as SPISIMOA
  75. GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA
  76. // GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 2; // Configure GPIO3 as SPISOMIA
  77. GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as SPICLKA
  78. GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; // Configure GPIO19 as SPISTEA
  79. EDIS;
  80. }
  81. #if DSP28_SPIB
  82. void InitSpibGpio()
  83. {
  84. EALLOW;
  85. /* Enable internal pull-up for the selected pins */
  86. // Pull-ups can be enabled or disabled disabled by the user.
  87. // This will enable the pullups for the specified pins.
  88. // Comment out other unwanted lines.
  89. GpioCtrlRegs.GPAPUD.bit.GPIO12 = 0; // Enable pull-up on GPIO12 (SPISIMOB)
  90. // GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; // Enable pull-up on GPIO24 (SPISIMOB)
  91. GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0; // Enable pull-up on GPIO13 (SPISOMIB)
  92. // GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0; // Enable pull-up on GPIO25 (SPISOMIB)
  93. GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0; // Enable pull-up on GPIO14 (SPICLKB)
  94. // GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0; // Enable pull-up on GPIO26 (SPICLKB)
  95. GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0; // Enable pull-up on GPIO15 (SPISTEB)
  96. // GpioCtrlRegs.GPAPUD.bit.GPIO27 = 0; // Enable pull-up on GPIO27 (SPISTEB)
  97. /* Set qualification for selected pins to asynch only */
  98. // This will select asynch (no qualification) for the selected pins.
  99. // Comment out other unwanted lines.
  100. GpioCtrlRegs.GPAQSEL1.bit.GPIO12 = 3; // Asynch input GPIO12 (SPISIMOB)
  101. // GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 3; // Asynch input GPIO24 (SPISIMOB)
  102. GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 3; // Asynch input GPIO13 (SPISOMIB)
  103. // GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 3; // Asynch input GPIO25 (SPISOMIB)
  104. GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 3; // Asynch input GPIO14 (SPICLKB)
  105. // GpioCtrlRegs.GPAQSEL2.bit.GPIO26 = 3; // Asynch input GPIO26 (SPICLKB)
  106. GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3; // Asynch input GPIO15 (SPISTEB)
  107. // GpioCtrlRegs.GPAQSEL2.bit.GPIO27 = 3; // Asynch input GPIO27 (SPISTEB)
  108. /* Configure SPI-B pins using GPIO regs*/
  109. // This specifies which of the possible GPIO pins will be SPI functional pins.
  110. // Comment out other unwanted lines.
  111. GpioCtrlRegs.GPAMUX1.bit.GPIO12 = 3; // Configure GPIO12 as SPISIMOB
  112. // GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 3; // Configure GPIO24 as SPISIMOB
  113. GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 3; // Configure GPIO13 as SPISOMIB
  114. // GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 3; // Configure GPIO25 as SPISOMIB
  115. GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 3; // Configure GPIO14 as SPICLKB
  116. // GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 3; // Configure GPIO26 as SPICLKB
  117. GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 3; // Configure GPIO15 as SPISTEB
  118. // GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 3; // Configure GPIO27 as SPISTEB
  119. EDIS;
  120. }
  121. #endif //endif DSP28_SPIB
  122. //===========================================================================
  123. // End of file.
  124. //===========================================================================