cancel
Showing results for 
Search instead for 
Did you mean: 

SPI receive, wrong LSB

NBlac
Associate III

I'm trying to communicate between the nucleoh743 (master mode) and a TDC GP22 slave chip but came across this issue:

I am expecting to read 0x27 but i always get 0x26. All the other bits from this 1 byte are correct so i was wondering if there something else that is wrong other than the slave device. Here is a pic from the logic analyzer. (CPOL=0, CPHA=1). The SPI init code was produced by cubemx.

HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_RESET);  // CS
		         HAL_Delay(1);
       HAL_SPI_Transmit(&hspi1, &tx, 1, 1);   // transmit 0xB5 from uint8_t tx
			 HAL_Delay(1);
       HAL_SPI_Receive(&hspi1, &rx, 1, 1);  // store in uint8_t rx
			 HAL_Delay(1);
       HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);  // CS
/* SPI1 init function */
static void MX_SPI1_Init(void)
{
 
  /* SPI1 parameter configuration*/
  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_128;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 7;
  hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
  hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
  hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi1.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
  hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
  hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
  hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
  hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
}

thanks

11 REPLIES 11
NBlac
Associate III

For what is worth, i changed the microcontroller to a stm32f4 and there are no more problems with the LA...

aasil
Associate II

Hi, i write a test code for gp22 , generated hal cube mx for stm32f107vctx..and my problem is a miso pin,miso pin is 0 ..i confused beacuse i connect a led to intn pin of gp22 and when send 0x03 for cal resonator its worked and give me a innterupt ...but miso any thing send...

please help me.