Hello friend,
I want to use gpio as CS because I have 3 SPI devices. I use frdmkw38_dspi_polling_b2b_transfer_master project. But the CS (PTA19) pin always high. I cannot control it to low. I modified some code as follows. Can anyone guide me? Thank you in advance.
Best wishes
Ted Wu
pin_mux.c
void BOARD_InitPins(void)
{
...
/* PORTA16 (pin 4) is configured as SPI1_SOUT */
PORT_SetPinMux(PORTA, 16U, kPORT_MuxAlt2);
/* PORTA17 (pin 5) is configured as SPI1_SIN */
PORT_SetPinMux(PORTA, 17U, kPORT_MuxAlt2);
/* PORTA18 (pin 6) is configured as SPI1_SCK */
PORT_SetPinMux(PORTA, 18U, kPORT_MuxAlt2);
/* PORTA19 (pin 7) is configured as SPI1_PCS0 */
PORT_SetPinMux(PORTA, 19U, kPORT_MuxAsGpio);
PORTA->PCR[19] = ((PORTA->PCR[19] &
/* Mask bits to zero which are setting */
(~(PORT_PCR_SRE_MASK | PORT_PCR_ISF_MASK)))
/* Slew Rate Enable: Fast slew rate is configured on the corresponding pin, if the pin is
* configured as a digital output. */
| PORT_PCR_SRE(kPORT_FastSlewRate));
....
}
dspi_polling_b2b_transfer_master.c
int main(void)
{
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
/* Define the init structure for the output pin */
gpio_pin_config_t gpio_1_config = {
kGPIO_DigitalOutput,
1,
};
...
srcClock_Hz = DSPI_MASTER_CLK_FREQ;
DSPI_MasterInit(EXAMPLE_DSPI_MASTER_BASEADDR, &masterConfig, srcClock_Hz);
/* Init output CS GPIO. */
GPIO_PinInit(GPIOA, 19U, &gpio_1_config);
while (1)
{
...
/* Start master transfer, send data to slave */
masterXfer.txData = masterTxData;
masterXfer.rxData = NULL;
masterXfer.dataSize = TRANSFER_SIZE;
masterXfer.configFlags = kDSPI_MasterCtar0;
GPIO_PinWrite(GPIOA, 1U << 19, 0);
DSPI_MasterTransferBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &masterXfer);
GPIO_PinWrite(GPIOA, 1U << 19, 1);
...
}
Solved! Go to Solution.
Hi,
Just as a quick test you can try the following:
In pin_mux.c > BOARD_InitPins(), add
PORT_SetPinMux(PORTC, 3U, kPORT_MuxAsGpio);
In dspi_transfer_master.c, add the following after pins and clock initialization:
gpio_pin_config_t gpio_as_cs = {
kGPIO_DigitalOutput,
1,
};
GPIO_PinInit(GPIOC, 3U, &gpio_as_cs);
After that, try writing the GPIO output:
GPIO_PinWrite(GPIOC, 3U, 0);
/* Delay */
for (i = 0U; i < EXAMPLE_DSPI_DEALY_COUNT; i++)
{
__NOP();
}
GPIO_PinWrite(GPIOC, 3U, 1);
You should see that the GPIO output level changes. However, please consider taking a look at the FRDM-KW38 schematics file to confirm that the pin you are trying to configure is not being used or connected to another module.
Please, let me know your findings.
Regards,
Eduardo.
If I use a single SPI, I can control the PTA19 (CS) potential level through the SPI program. But I have 3 SPI devices. I want to use gpio as CS (chip select) to distinguish which SPI is used at a time. So I want to use gpio as CS. But if I use gpio as CS I can't control it.
Best wishes
Ted Wu
Hi,
Just as a quick test you can try the following:
In pin_mux.c > BOARD_InitPins(), add
PORT_SetPinMux(PORTC, 3U, kPORT_MuxAsGpio);
In dspi_transfer_master.c, add the following after pins and clock initialization:
gpio_pin_config_t gpio_as_cs = {
kGPIO_DigitalOutput,
1,
};
GPIO_PinInit(GPIOC, 3U, &gpio_as_cs);
After that, try writing the GPIO output:
GPIO_PinWrite(GPIOC, 3U, 0);
/* Delay */
for (i = 0U; i < EXAMPLE_DSPI_DEALY_COUNT; i++)
{
__NOP();
}
GPIO_PinWrite(GPIOC, 3U, 1);
You should see that the GPIO output level changes. However, please consider taking a look at the FRDM-KW38 schematics file to confirm that the pin you are trying to configure is not being used or connected to another module.
Please, let me know your findings.
Regards,
Eduardo.
Hello @tedwu1
Hope you are doing well.
According to the FRDM-KW38 schematics (which can be downloaded from the FRDM-KW38 webpage, Design Files section), PTA19 should be connected to FXOS8700CQ Combo Sensor Pin 11 (INT1). Please, consider using another pin as GPIO for your application.
Regards,
Eduardo.