yefj
Advanced Member level 4
Hello, I want to create a 4 byte SPI transmition,so i need my Chip select to be manual.
My Chip Select is PC9 as shown in the photo bellow from the starter kit manual.
I have connected my scope to Chip select and CLK.
At first as you can see bellow that When i have AUTO CS the SPI picture is fine.
But when i made autoCsEnable false, And i tried to do manual GPIO controlling of PC9 ,it didnt allow me that.
I even could not make PC9 to be VDD,and the most amazing thing is that i have built before almost identical code for EFM32 and it worked fine.
Where did i go wrong?
Thanks.
My Chip Select is PC9 as shown in the photo bellow from the starter kit manual.
I have connected my scope to Chip select and CLK.
At first as you can see bellow that When i have AUTO CS the SPI picture is fine.
But when i made autoCsEnable false, And i tried to do manual GPIO controlling of PC9 ,it didnt allow me that.
I even could not make PC9 to be VDD,and the most amazing thing is that i have built before almost identical code for EFM32 and it worked fine.
Where did i go wrong?
Thanks.
Code:
#include "em_device.h"
#include "em_chip.h"
#include "em_cmu.h"
#include "em_gpio.h"
#include "em_usart.h"
#define TX_BUFFER_SIZE 4
#define RX_BUFFER_SIZE TX_BUFFER_SIZE
uint8_t com1[TX_BUFFER_SIZE] = {0x03,0x0F,0xFF,0xF0};
uint8_t RxBuffer[RX_BUFFER_SIZE];
/**************************************************************************//**
* @brief Initialize USART1
*****************************************************************************/
void initUSART1 (void)
{
CMU_ClockEnable(cmuClock_GPIO, true);
CMU_ClockEnable(cmuClock_USART1, true);
// Configure GPIO mode
GPIO_PinModeSet(gpioPortC, 8, gpioModePushPull, 0); // US1_CLK is push pull
GPIO_PinModeSet(gpioPortC, 9, gpioModePushPull, 1); // US1_CS is push pull
GPIO_PinModeSet(gpioPortC, 6, gpioModePushPull, 1); // US1_TX (MOSI) is push pull
GPIO_PinModeSet(gpioPortC, 7, gpioModeInput, 1); // US1_RX (MISO) is input
// GPIO_PinModeSet(gpioPortA, 0, gpioModePushPull, 1); //delay
// Start with default config, then modify as necessary
USART_InitSync_TypeDef config = USART_INITSYNC_DEFAULT;
config.master = true; // master mode
config.baudrate = 1000000; // CLK freq is 1 MHz
config.autoCsEnable = false; // CS pin controlled by hardware, not firmware
config.clockMode = usartClockMode1; // clock idle low, sample on rising/first edge
config.msbf = true; // send MSB first
config.enable = usartDisable; // Make sure to keep USART disabled until it's all set up
USART_InitSync(USART1, &config);
// Set USART pin locations
USART1->ROUTELOC0 = (USART_ROUTELOC0_CLKLOC_LOC11) | // US1_CLK on location 11 = PC8 per datasheet section 6.4 = EXP Header pin 8
(USART_ROUTELOC0_CSLOC_LOC11) | // US1_CS on location 11 = PC9 per datasheet section 6.4 = EXP Header pin 10
(USART_ROUTELOC0_TXLOC_LOC11) | // US1_TX (MOSI) on location 11 = PC6 per datasheet section 6.4 = EXP Header pin 4
(USART_ROUTELOC0_RXLOC_LOC11); // US1_RX (MISO) on location 11 = PC7 per datasheet section 6.4 = EXP Header pin 6
// Enable USART pins
USART1->ROUTEPEN = USART_ROUTEPEN_CLKPEN | USART_ROUTEPEN_CSPEN | USART_ROUTEPEN_TXPEN | USART_ROUTEPEN_RXPEN;
// Enable USART1
USART_Enable(USART1, usartEnable);
}
/**************************************************************************//**
* @brief Main function
*****************************************************************************/
int main(void)
{
uint32_t i;
// Initialize chip
CHIP_Init();
// Initialize USART1 as SPI slave
initUSART1();
GPIO_PinOutSet(gpioPortC,9);
for(i=0;i<115;i++)//delay loop for making stable PC9
{
GPIO_PinOutSet(gpioPortA,5);
GPIO_PinOutClear(gpioPortA,5);
}
while(1)
{
GPIO_PinOutClear(gpioPortC,9);
USART_SpiTransfer(USART1,com1[0]);
USART_SpiTransfer(USART1,com1[1]);
USART_SpiTransfer(USART1,com1[2]);
USART_SpiTransfer(USART1,com1[3]);
GPIO_PinOutSet(gpioPortC,9);
for(i=0;i<115;i++)//delay loop for making stable PC9
{
GPIO_PinOutSet(gpioPortA,5);
GPIO_PinOutClear(gpioPortA,5);
}
}
}
Last edited: