1

I am trying to make connection by HAL_SPI_*() API with mfrc522 and at least read VersionReg register , but what address I want to read return its address in data in other words it seems to has a echo!

Here is my SPI initialisation:

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_32;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
    Error_Handler();
}

and here is my function to read a register:

 HAL_GPIO_WritePin(RD_SS_Port, RD_SS_Pin, GPIO_PIN_RESET);
 Address=0x37;
 ucAddr = ((Address<<1)&0x7E)|0x80;
// ucAddr=0xb7;
 d[0]=ucAddr;
while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY) { }
if (HAL_SPI_Transmit(&hspi1,d,2,20) != HAL_OK)
{
    printf("send error\r\n");
}

while(HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY) { }
if (HAL_SPI_Receive(&hspi1,r,1,20) != HAL_OK)
{
     printf("Receive error\r\n");
}

//  printf("i2=%x s[0]=%x r[0]=%x r[1]=%x \r\n",i,s[0],r[0],r[1]);
   ucResult=r[0];
return ucResult;

I will appreciate if some one can help me.

0andriy
  • 4,183
  • 1
  • 24
  • 37

1 Answers1

0

Actually the first read is ok and I can read VersionReg once after reset . but even when I put it in a loop , just the first read is ok(0x92) and the others read (0xee) which is the thing I have sent to it.