Page 1 of 1

Little SPI Chip Select problem

Posted: Tue Nov 19, 2013 10:35 pm
by Flo89
Good evening everybody :)

I had a little SPI (test)program running under ChibiOs 2.6.1 on STM32F30x and now I'm trying to get it running on STM32F4xx.
Mosi and Clock lines are working good but CS remains always low level. I tried with 'Software slave management disabled' and 'enabled in the SPI_CR1 register.
Here is my little test code and perhaps somebody sees an error immediatly?

Code: Select all

static const SPIConfig spi1cfg = {
  NULL,
  /* HW dependent part.*/
  GPIOA,
  4,
  0b0000101000010100             //or 0b0000100000010100 for NSS hard?
};

/*
 * Gyroscope (SPI1) Startup code
 * See documentation
*/
static uint16_t txbuf[7]={42784,1313,34,4131,36,168,143};
static uint16_t rxbuf[7];

void write_read_buffer_spi_gyroscope (uint16_t *transmit,uint16_t *receive){
    spiSelect(&SPID1);                  /* Slave Select assertion.          */
    spiExchange(&SPID1, 1*2,
                transmit, receive);          /* Atomic transfer operations.      */
    spiUnselect(&SPID1);                /* Slave Select de-assertion.       */
   }

/*
 * Application entry point.
 */
int main(void) {
  halInit();
  chSysInit();
  spiStart(&SPID1, &spi1cfg);       /* Setup transfer parameters.       */
  write_read_buffer_spi_gyroscope(&txbuf[0],&rxbuf[0]);
  write_read_buffer_spi_gyroscope(&txbuf[1],&rxbuf[1]);
  write_read_buffer_spi_gyroscope(&txbuf[2],&rxbuf[2]);
  write_read_buffer_spi_gyroscope(&txbuf[3],&rxbuf[3]);
  write_read_buffer_spi_gyroscope(&txbuf[4],&rxbuf[4]);
  write_read_buffer_spi_gyroscope(&txbuf[5],&rxbuf[5]);
  write_read_buffer_spi_gyroscope(&txbuf[6],&rxbuf[6]);
 ...


Thank you!!!

Re: Little SPI Chip Select problem

Posted: Tue Nov 19, 2013 10:47 pm
by Giovanni
Hi,

spiSelect() and spiUnselect() operate on normal GPIO pins, is your chip select a GPIO? also, you don't need to set the CS mode in the CR1 register. I suggest to start from the SPI demo under ./testhal/STM32F4 and use a similar configuration.

Giovanni

Re: Little SPI Chip Select problem

Posted: Tue Nov 19, 2013 11:07 pm
by Flo89
Oh oh,

I just forgot to initialize the four pins... :D
Sorry for the disturbance and thanks a lot for the fast help!!