2017-12-11 05:21 AM
Hello dear STM32.
I have problem with SPI communicatoin on my nucleo32 board with STM32 l432kc. Already 2 days, I am trying to make SPI communicatin work, but without any result. When I was measuring with my Osciloscope, I saw something just on MOSI. On SCK there was no signal. I need just transmit some data on my display (I am trying to communicate with display dogs102-6 ->
http://www.lcd-module.com/eng/pdf/grafik/dogs102-6e.pdf
). But wit osciloscopeCan anyone help me please ?
:(
Thanks for any help .
Here is my code:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_SMBUS_Init();
MX_SPI1_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
initDisplay();
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
initDisplay();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
/* SPI1 init function */
static void MX_SPI1_Init(void)
{
__HAL_RCC_SPI1_CLK_ENABLE();
hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER;
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
hspi1.Init.DataSize = SPI_DATASIZE_8BIT ;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
//-------------------------------------------------------------------------------------------------
/* USER CODE BEGIN 4 */
void initDisplay(){
/*
uint32_t CD = GPIO_PIN_8;
uint32_t RST = GPIO_PIN_9;
uint32_t CS0 = GPIO_PIN_10;
uint32_t LCDBacklight = GPIO_PIN_11;
*/
uint8_t configData[13] = {0x40, 0xA1, 0xC0, 0xA4, 0xA6, 0xA2, 0x2F, 0x27, 0x81, 0x10, 0xFA, 0x90, 0xAF};
uint8_t data[1] = {0b11111111};
__HAL_RCC_SPI1_CLK_ENABLE();
HAL_Delay(100);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_9, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET);
HAL_Delay(100);
HAL_SPI_Transmit(&hspi1, configData, 13, 500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
HAL_Delay(100);
HAL_SPI_Transmit(&hspi1, data, 1,500);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
}
#clk-spi-problem #spi #spi_transmit #hal_spi_transmit2017-12-11 10:57 PM
Check that there are no conflicts with connections on the board (Nucleo boards are relatively sparse but it never hurts to check).
Read out and check/post the content of relevant SPI and GPIO registers.
JW
2017-12-12 02:24 AM
Thank you very much for your reply !!
I checked the connection and tried to change SCK (In cubeMX ).
Can I ask, what should be the frequency of SCK. Becouse I have Osciloscope that can measure set frequency without problem(
http://www.hantek.com/en/ProductDetail_123
)hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_256
That is wierd, becouse I remember that, when I was setting up the frequency, it was in kHz.
BUT, when i connected diode between GND and new SCK, that diode blinked for a moment, when data was transfering. So I think, SCK is just on some realy high frequency, that ma Scope can not measure. But my scope has bandwidth 100 Mhz. So I think that is wierd.
Thanks for any help
2017-12-12 02:55 AM
Read out and check/post the content of relevant SPI and GPIO registers.