2019-01-30 04:44 AM
The problem is that the (working) TI DVM board starts the MOSI communication one half clk cycle before I manage to do it with my Nucleo-F030R8 so the the information gets bit-shifted into the chip and miss-interpreted.
I'm using HAL and I've tried every different setting available with no luck. What am I missing here?
The analyser plots attached pretty much sums it up.
I would be very grateful if you could help me. :smiling_face_with_smiling_eyes:
uint8_t Cmd[1] = {0x80};
HAL_GPIO_WritePin(SPI_CS_GPIO_Port,SPI_CS_Pin,SET);
HAL_Delay(2);
HAL_SPI_Transmit(&hspi1, Cmd, 1, 0xFF);
HAL_GPIO_WritePin(SPI_CS_GPIO_Port,SPI_CS_Pin,RESET);
//settings
void MX_SPI1_Init(void)
{
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_2EDGE;
hspi1.Init.NSS = SPI_NSS_SOFT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_ENABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
Error_Handler();
}
}
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(spiHandle->Instance==SPI1)
{
/* USER CODE BEGIN SPI1_MspInit 0 */
/* USER CODE END SPI1_MspInit 0 */
/* SPI1 clock enable */
__HAL_RCC_SPI1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/**SPI1 GPIO Configuration
PA6 ------> SPI1_MISO
PA7 ------> SPI1_MOSI
PB3 ------> SPI1_SCK
*/
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF0_SPI1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* SPI1 interrupt Init */
HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(SPI1_IRQn);
/* USER CODE BEGIN SPI1_MspInit 1 */
/* USER CODE END SPI1_MspInit 1 */
}
}
2019-01-30 05:00 AM
SPI have option for not using TI nss pulse mode, maybe this could help make the communication work? Try and compare. Usually it is related to data sampling clock edge
2019-01-30 05:03 AM
Hello!
Thanks for your showed interest.
I think that option is already activated:
hspi1.Init.TIMode = SPI_TIMODE_ENABLE;
2019-01-30 05:51 AM
Try disabling it. Then check which clock polarity works. Polarity and phase are adjustable. You can control the nss gpio manually by sw.
2019-01-30 05:53 AM
Tooodelou! =)
Sometimes, just taking a break and write onto a public forum, get's you going again. Without knowing to much in the low parts of SPI this is what got it working with my particular TI DRV8308:
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_128;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
I just post it for future references.
The strange part about this is that when I read about the difference between TI and Motorola, it struck me that this particular IC was more like Motorola than TI. There is a good post on this forum describing some user having problem with TI DRV8305, and reading that datasheet reveals that that IC has a completely different SPI, more TI like.
https://community.st.com/s/question/0D50X00009XkYMnSAN/stm32f334-spi-ti-mode
2019-01-30 05:59 AM
Making progress, great!