2017-02-16 02:07 PM
I am trying to make RC522 (RFID) work on STM32F0 discovery board. I read the arduino library which can be useful, before starting I am trying to make SPI work.
I have connected all the pins to STM32F0 and CS pin is handled manually not by NSS pin of SPI.
I am trying to read the firmware of the RC522 module. According to the datasheet it should reply with either 0x91 or 0x92. I am not getting any of these but some strange values like 0x24 or 0xA4. I used STM32 CubeMx to generate the Basic code. Here is my SPI initialization code :-
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_HIGH; hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; hspi1.Init.NSS = SPI_NSS_SOFT; hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; 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_DISABLE; if (HAL_SPI_Init(&hspi1) != HAL_OK) { Error_Handler(); }Here is my simple code to read the firmware version :-
uint8_t address,value;
address = (((0x37 << 1) & 0x7E) | 0x80); while (1) { HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_RESET); HAL_SPI_Transmit(&hspi1,&address,1,50); HAL_SPI_Receive(&hspi1,&value,1,50); HAL_SPI_Transmit(&hspi1,0x00,1,50); // Stop Reading HAL_GPIO_WritePin(CS_GPIO_Port,CS_Pin,GPIO_PIN_SET); HAL_Delay(50); } #rc522 #stm322017-02-18 07:52 AM
If available, check the signals on an oscilloscope.