0

I'm trying to send data through spi with the Stm8 controller. The problem is that I can't see anything happening on the oscilloscope (even the SPI clock doesn't show) on the pins 6 and 5 with this code:

#include "stm8l15x_spi.h"
#include "imagedata.h"
#include "delay.h"
#include "stm8l15x.h"

void initSPIMaster(void);

This is how I try to call the functions in the main:

void main(void)
{ CLK_PeripheralClockConfig(CLK_Peripheral_SPI1, ENABLE);
  initSPIMaster();  
  SPI_BiDirectionalLineConfig(SPI1, SPI_Direction_Tx); //Selects the data transfer direction 

  SPI_SendData(SPI1, 0xCD); }

Here is how I configured the pins on the board and the SPI_SendData function:

void initSPIMaster()
{
    
GPIO_Init( GPIOB ,GPIO_Pin_7, GPIO_Mode_In_PU_No_IT ); //Miso input
GPIO_Init( GPIOB, GPIO_Pin_6, GPIO_Mode_Out_PP_Low_Fast); //MOSI
GPIO_Init( GPIOB, GPIO_Pin_5, GPIO_Mode_Out_PP_Low_Fast); //CLK
GPIO_Init( GPIOB, GPIO_Pin_4, GPIO_Mode_Out_PP_Low_Fast); //CS

GPIOB->DDR = (1<<GPIO_Pin_6)| (0<<GPIO_Pin_7);  //MOSI output, MISO input
GPIOB->DDR |= (1<<GPIO_Pin_5); //SCK output
GPIOB->CR1  = (1<<GPIO_Pin_6)| (1<<GPIO_Pin_5); //MOSI push-pull & SCK
//GPIOB->CR1    = (1<<GPIO_Pin_5); 

GPIOB->DDR |= (1<<GPIO_Pin_4); //set CS as output
GPIOB->CR1 |= (1<<GPIO_Pin_4); //set CS as push-pull*/
  
}



void SPI_SendData(SPI_TypeDef* SPIx, uint8_t Data) //declared in the stm8l15x_spi.h
{
  SPIx->DR = Data; /* Write in the DR register the data to be sent*/
}

I checked if the pins are wrongly configured but this should be right according to the datasheet of this board. Maybe I missed something in this code. Unfortunetaly there isn't much information about this topic on the internet but hopefully I can find a solution here. Does anyone know how to do this?

  • 1
    "The problem is that I can't see anything happening on the oscillator" As in you measured it with an oscilloscope, or...? What kind of oscillator are you using? It's also unclear if you speak of the SPI clock signal or the main MCU clock, or both? – Lundin Nov 24 '22 at 12:38
  • 2
    How are `GPIO_Pin_7` etc defined? Are you sure it is `7` and not actually `0x80`? Because `1 << 0x40` etc isn't going to end well. Have you viewed the DDR etc registers in your debugger? – Lundin Nov 24 '22 at 12:42

0 Answers0