Dear fellow engineer.
Does anybody know how to set SPI pin as GIO pin and change the value in the source code?
Best Regards.
Dzoelham
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Dear fellow engineer.
Does anybody know how to set SPI pin as GIO pin and change the value in the source code?
Best Regards.
Dzoelham
In HALCoGen, enable the SPI and GIO driver,
Then, on the SPI TAB,
there is a SPIX Port subtab,
on that tab, you can select if the SPI port is GIO.
Take care that you call gioInit() and spiInit()
You can use the gio functions to talk to the pins. Pass the SPI port and pin numbers.
It works just like a standard gio pin.
There is an example somewhere from TI on how to use HET as general GIO. The same applies here.
I have attached a HALCoGen and CCSv6 project that toggles the SPI1 SOMI pin using gioToggleBit().
sys_main.c:
/* USER CODE BEGIN (1) */ #include "gio.h" #include "spi.h" /* USER CODE END */ /* USER CODE BEGIN (3) */ uint32_t wait_counter = 0; gioInit(); spiInit(); // toggle the SPI1 SOMI port with GIO while (1) { gioToggleBit(spiPORT1, 11); for(wait_counter=0;wait_counter< 40000;wait_counter++); //wait some time. } /* USER CODE END */
the example project that I have attached above has a comment that indicates what section of the datasheet has that info.
you can also have a look at the source file spi.c. By looking at it you can derive the pin assignments. They are commented in the spiInit() code.
In spnu517a.pdf ,p. 879:
Table 21-11. SPI Pin Control Register 2 (SPIPC2) Field Descriptions
in spi.c:
/** - SPI1 Port output values */ spiREG1->PC3 = (uint32)((uint32)1U << 0U) /* SCS[0] */ | (uint32)((uint32)1U << 1U) /* SCS[1] */ | (uint32)((uint32)1U << 2U) /* SCS[2] */ | (uint32)((uint32)1U << 3U) /* SCS[3] */ | (uint32)((uint32)0U << 8U) /* ENA */ | (uint32)((uint32)0U << 9U) /* CLK */ | (uint32)((uint32)0U << 10U) /* SIMO[0] */ | (uint32)((uint32)0U << 11U); /* SOMI[0] */
You use the same gioSetBit() api.
As first parameter, take the port of the (MIBSPI/SPI) pin you want to drive, and as second parameter the bit for that particular pin.
If your pin is on (MIB)SPI 1, and you enabled the MIBSPI driver for module 1, the port is called mibspiPORT1 .
If you enabled the SPI driver for module 1, the port is called spiPORT1 .
side note: these are actually the very same address locations. Here is their definition created by HALCoGen
#define mibspiPORT1 ((gioPORT_t *)0xFFF7F418U)
#define spiPORT1 ((gioPORT_t *)0xFFF7F418U)