Hello everyone,
This is my first question ever, sorry voor my bad english. Im just started to work with a STMF429I discovery board and a NRF52832(isp1507) BLE chip. Im trying to make a SPI bridge between them, but i fail every time. The NRF52832 is my slave(SPIS), and the STM32F429 is my master(SPIM).
fore the slave i use the SPIS example from the nRF5_SDK_14.0.0 and added a NRF_log so i can see that in in the buffers. This all in Keil U5.
fore the master i use the CUBEmx fore all the pins and SPIm with all the hall liberays. this all in atollic.
The slave nrf52 gets almost nothing, only somtime a couple of letters from the test string. the master stm32 gets the half of the string and then DEF symbol. so i know there is connection only there is somting wrong with the delay/semaphore, but i can not figgure out what it is.
does anyone know what im doing wrong? if you need more information pleas let me know.\
kind regards Sem
below here are the code's
NRF52832 code
#define SPIS_INSTANCE 1 /**< SPIS instance index. */
#define NRF_LOG_ENABLED 1
#define NRF_LOG_BACKEND_SERIAL_USES_UART 1
#define APP_SPIS_CS_PIN 4
#define APP_SPIS_MISO_PIN 6
#define APP_SPIS_MOSI_PIN 7
#define APP_SPIS_SCK_PIN 8
static const nrf_drv_spis_t spis = NRF_DRV_SPIS_INSTANCE(SPIS_INSTANCE);/**< SPIS instance. */
#define TEST_STRING "TESTnaarSTM"
static uint8_t m_tx_buf[] = TEST_STRING; /**< TX buffer. */
static uint8_t m_rx_buf[sizeof(TEST_STRING)]; /**< RX buffer. */
static const uint8_t m_length = sizeof(m_tx_buf); /**< Transfer length. */
static volatile bool spis_xfer_done; /**< Flag used to indicate that SPIS instance completed the transfer. */
void spis_event_handler(nrf_drv_spis_event_t event)
{
if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
{
spis_xfer_done = true;
NRF_LOG_INFO(" Transfer completed. Received: %s",(uint32_t)m_rx_buf);
NRF_LOG_INFO(" What is send from buffer TX : %s", m_tx_buf );
}
}
int main(void)
{
NRF_POWER->TASKS_LOWPWR = 1;
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("Main available.");
NRF_LOG_FLUSH();
nrf_drv_spis_config_t spis_config = NRF_DRV_SPIS_DEFAULT_CONFIG;
spis_config.csn_pin = APP_SPIS_CS_PIN;
spis_config.miso_pin = APP_SPIS_MISO_PIN;
spis_config.mosi_pin = APP_SPIS_MOSI_PIN;
spis_config.sck_pin = APP_SPIS_SCK_PIN;
NRF_LOG_INFO("Main pins connected.");
NRF_LOG_INFO("Main what is going to send from buffer TX : %s", m_tx_buf );
NRF_LOG_FLUSH();
APP_ERROR_CHECK(nrf_drv_spis_init(&spis, &spis_config, spis_event_handler));
while (1)
{
memset(m_rx_buf, 0, m_length);
spis_xfer_done = false;
APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length));
NRF_LOG_INFO("*********************");
NRF_LOG_INFO("*********************");
NRF_LOG_FLUSH();
while (!spis_xfer_done)
{
//NRF_LOG_INFO("staat stil idle te doen");
//NRF_LOG_FLUSH();
__WFE();
}
}
}
STM32F429 Code
#define TESTSTRING "TESTnaarBLE"
SPI_HandleTypeDef hspi4;
UART_HandleTypeDef huart1;
uint8_t aTxBuffer[] = TESTSTRING;
uint8_t aRxBuffer[sizeof(TESTSTRING)];
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI4_Init(void);
static void MX_USART1_UART_Init(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_SPI4_Init();
MX_USART1_UART_Init();
HAL_StatusTypeDef status;
HAL_GPIO_WritePin(BLE_SPI4_SS_GPIO_Port, BLE_SPI4_SS_Pin, GPIO_PIN_RESET);
HAL_Delay(500);
if((status = HAL_SPI_TransmitReceive(&hspi4, aTxBuffer, aRxBuffer, sizeof(aTxBuffer), 1000)) != HAL_OK)
{
Error_Handler();
}
HAL_Delay(500);
HAL_GPIO_WritePin(BLE_SPI4_SS_GPIO_Port, BLE_SPI4_SS_Pin, GPIO_PIN_SET);
uint32_t error = HAL_SPI_GetError(&hspi4);
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 4;
RCC_OscInitStruct.PLL.PLLN = 168;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
static void MX_SPI4_Init(void)
{
hspi4.Instance = SPI4;
hspi4.Init.Mode = SPI_MODE_MASTER;
hspi4.Init.Direction = SPI_DIRECTION_2LINES;
hspi4.Init.DataSize = SPI_DATASIZE_8BIT;
hspi4.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi4.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi4.Init.NSS = SPI_NSS_SOFT;
hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi4.Init.TIMode = SPI_TIMODE_DISABLE;
hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi4.Init.CRCPolynomial = 10;
if (HAL_SPI_Init(&hspi4) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(BLE_SPI4_SS_GPIO_Port, BLE_SPI4_SS_Pin, GPIO_PIN_SET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(LED_GREEN_GPIO_Port, LED_GREEN_Pin, GPIO_PIN_RESET);
/*Configure GPIO pin : BLE_SPI4_SS_Pin */
GPIO_InitStruct.Pin = BLE_SPI4_SS_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(BLE_SPI4_SS_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : LED_RED_Pin */
GPIO_InitStruct.Pin = LED_RED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_RED_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : LED_GREEN_Pin */
GPIO_InitStruct.Pin = LED_GREEN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_GREEN_GPIO_Port, &GPIO_InitStruct);
}
void _Error_Handler(char * file, int line)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* rode led gaat aan is error ! */
HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_SET );
HAL_Delay(1000);
HAL_GPIO_WritePin(LED_RED_GPIO_Port, LED_RED_Pin, GPIO_PIN_RESET );
HAL_Delay(1000);
while(1)
{
}
/* USER CODE END Error_Handler_Debug */
}