Attempt to replicate the initialization sequence of an arduino project.
This commit is contained in:
125
main.c
125
main.c
@@ -29,46 +29,8 @@ static void mfrc522_integration_irq_init(mfrc522_handle_t* const ctx)
|
||||
mfrc522_integration_irq_handler);
|
||||
}
|
||||
|
||||
void mfrc522_integration_init(void)
|
||||
void setup_attempt_1(void)
|
||||
{
|
||||
DRIVER_MFRC522_LINK_INIT(&ctx, mfrc522_handle_t);
|
||||
DRIVER_MFRC522_LINK_RESET_GPIO_INIT(&ctx, mfrc522_interface_reset_gpio_init);
|
||||
DRIVER_MFRC522_LINK_RESET_GPIO_DEINIT(&ctx, mfrc522_interface_reset_gpio_deinit);
|
||||
DRIVER_MFRC522_LINK_RESET_GPIO_WRITE(&ctx, mfrc522_interface_reset_gpio_write);
|
||||
DRIVER_MFRC522_LINK_IIC_INIT(&ctx, mfrc522_interface_iic_init);
|
||||
DRIVER_MFRC522_LINK_IIC_DEINIT(&ctx, mfrc522_interface_iic_deinit);
|
||||
DRIVER_MFRC522_LINK_IIC_WRITE(&ctx, mfrc522_interface_iic_write);
|
||||
DRIVER_MFRC522_LINK_IIC_READ(&ctx, mfrc522_interface_iic_read);
|
||||
DRIVER_MFRC522_LINK_UART_INIT(&ctx, mfrc522_interface_uart_init);
|
||||
DRIVER_MFRC522_LINK_UART_DEINIT(&ctx, mfrc522_interface_uart_deinit);
|
||||
DRIVER_MFRC522_LINK_UART_READ(&ctx, mfrc522_interface_uart_read);
|
||||
DRIVER_MFRC522_LINK_UART_WRITE(&ctx, mfrc522_interface_uart_write);
|
||||
DRIVER_MFRC522_LINK_UART_FLUSH(&ctx, mfrc522_interface_uart_flush);
|
||||
DRIVER_MFRC522_LINK_SPI_INIT(&ctx, mfrc522_interface_spi_init);
|
||||
DRIVER_MFRC522_LINK_SPI_DEINIT(&ctx, mfrc522_interface_spi_deinit);
|
||||
DRIVER_MFRC522_LINK_SPI_READ(&ctx, mfrc522_interface_spi_read);
|
||||
DRIVER_MFRC522_LINK_SPI_WRITE(&ctx, mfrc522_interface_spi_write);
|
||||
DRIVER_MFRC522_LINK_DELAY_MS(&ctx, mfrc522_interface_delay_ms);
|
||||
DRIVER_MFRC522_LINK_DEBUG_PRINT(&ctx, mfrc522_interface_debug_print);
|
||||
DRIVER_MFRC522_LINK_RECEIVE_CALLBACK(&ctx, mfrc522_interface_receive_callback);
|
||||
|
||||
mfrc522_set_interface(&ctx, MFRC522_INTERFACE_SPI);
|
||||
uint8_t init_retval = mfrc522_init(&ctx);
|
||||
|
||||
if (init_retval != 0) {
|
||||
mfrc522_interface_debug_print("ERR: %s failed: %d\n", __FUNCTION__, init_retval);
|
||||
}
|
||||
|
||||
// Set IRQ pin of MFRC522 to CMOS, enable irq on pico on success
|
||||
uint8_t irq_pin_type_ret = mfrc522_set_interrupt_pin_type(&ctx, MFRC522_INTERRUPT_PIN_TYPE_STANDARD_CMOS);
|
||||
if (irq_pin_type_ret != 0) {
|
||||
mfrc522_interface_debug_print("ERR: Could not set interrupt pin type.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
mfrc522_integration_irq_init(&ctx);
|
||||
}
|
||||
|
||||
// Set rf uart to 106000 baud (tx/rx)
|
||||
uint8_t set_tx_speed_ret = mfrc522_set_tx_speed(&ctx, MFRC522_SPEED_106_KBD);
|
||||
if (set_tx_speed_ret != 0) {
|
||||
@@ -164,6 +126,91 @@ void mfrc522_integration_init(void)
|
||||
if (analog_enable_retval != 0) {
|
||||
mfrc522_interface_debug_print("ERR: Enabling analog receiver failed: %d\n", analog_enable_retval);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// follows setup strategy of arduino lib
|
||||
void setup_attempt_2(void)
|
||||
{
|
||||
/*
|
||||
_dev->PCD_WriteRegister(TModeReg, 0x80); // TAuto=1; timer starts automatically at the end of the transmission in all communication modes at all speeds
|
||||
_dev->PCD_WriteRegister(TPrescalerReg, 0xA9); // TPreScaler = TModeReg[3..0]:TPrescalerReg, ie 0x0A9 = 169 => f_timer=40kHz, ie a timer period of 25μs.
|
||||
_dev->PCD_WriteRegister(TReloadRegH, 0x03); // Reload timer with 0x3E8 = 1000, ie 25ms before timeout.
|
||||
_dev->PCD_WriteRegister(TReloadRegL, 0xE8);
|
||||
|
||||
_dev->PCD_WriteRegister(TxASKReg, 0x40); // Default 0x00. Force a 100 % ASK modulation independent of the ModGsPReg register setting
|
||||
_dev->PCD_WriteRegister(ModeReg, 0x3D); // Default 0x3F. Set the preset value for the CRC coprocessor for the CalcCRC command to 0x6363 (ISO 14443-3 part 6.2.4)
|
||||
*/
|
||||
|
||||
// PCD Setup part
|
||||
uint8_t new_tmodereg = 0x80;
|
||||
(void) mfrc522_set_reg(&ctx, 0x2A, &new_tmodereg, sizeof(new_tmodereg));
|
||||
uint8_t new_tprescalerreg = 0xA9;
|
||||
(void) mfrc522_set_reg(&ctx, 0x2B, &new_tprescalerreg, sizeof(new_tprescalerreg));
|
||||
uint8_t new_treloadregh = 0x03;
|
||||
(void) mfrc522_set_reg(&ctx, 0x2C, &new_treloadregh, sizeof(new_treloadregh));
|
||||
uint8_t new_treloadregl = 0xE8;
|
||||
(void) mfrc522_set_reg(&ctx, 0x2D, &new_treloadregl, sizeof(new_treloadregl));
|
||||
uint8_t new_txaskreg = 0x40;
|
||||
(void) mfrc522_set_reg(&ctx, 0x15, &new_txaskreg, sizeof(new_txaskreg));
|
||||
uint8_t new_modereg = 0x3D;
|
||||
(void) mfrc522_set_reg(&ctx, 0x11, &new_modereg, sizeof(new_modereg));
|
||||
|
||||
// Enable antenna
|
||||
uint8_t current_txcontrolreg = 0;
|
||||
(void) mfrc522_get_reg(&ctx, 0x14, ¤t_txcontrolreg, sizeof(current_txcontrolreg));
|
||||
if ((current_txcontrolreg & 0x03) != 0x03) {
|
||||
uint8_t new_txcontrolreg = current_txcontrolreg | 0x03;
|
||||
(void) mfrc522_set_reg(&ctx, 0x14, &new_txcontrolreg, sizeof(new_txcontrolreg));
|
||||
}
|
||||
|
||||
// Allow ... irq to be propagated
|
||||
uint8_t new_comienreg = 0xA0;
|
||||
(void) mfrc522_set_reg(&ctx, 0x02, &new_comienreg, sizeof(new_comienreg));
|
||||
}
|
||||
|
||||
void mfrc522_integration_init(void)
|
||||
{
|
||||
DRIVER_MFRC522_LINK_INIT(&ctx, mfrc522_handle_t);
|
||||
DRIVER_MFRC522_LINK_RESET_GPIO_INIT(&ctx, mfrc522_interface_reset_gpio_init);
|
||||
DRIVER_MFRC522_LINK_RESET_GPIO_DEINIT(&ctx, mfrc522_interface_reset_gpio_deinit);
|
||||
DRIVER_MFRC522_LINK_RESET_GPIO_WRITE(&ctx, mfrc522_interface_reset_gpio_write);
|
||||
DRIVER_MFRC522_LINK_IIC_INIT(&ctx, mfrc522_interface_iic_init);
|
||||
DRIVER_MFRC522_LINK_IIC_DEINIT(&ctx, mfrc522_interface_iic_deinit);
|
||||
DRIVER_MFRC522_LINK_IIC_WRITE(&ctx, mfrc522_interface_iic_write);
|
||||
DRIVER_MFRC522_LINK_IIC_READ(&ctx, mfrc522_interface_iic_read);
|
||||
DRIVER_MFRC522_LINK_UART_INIT(&ctx, mfrc522_interface_uart_init);
|
||||
DRIVER_MFRC522_LINK_UART_DEINIT(&ctx, mfrc522_interface_uart_deinit);
|
||||
DRIVER_MFRC522_LINK_UART_READ(&ctx, mfrc522_interface_uart_read);
|
||||
DRIVER_MFRC522_LINK_UART_WRITE(&ctx, mfrc522_interface_uart_write);
|
||||
DRIVER_MFRC522_LINK_UART_FLUSH(&ctx, mfrc522_interface_uart_flush);
|
||||
DRIVER_MFRC522_LINK_SPI_INIT(&ctx, mfrc522_interface_spi_init);
|
||||
DRIVER_MFRC522_LINK_SPI_DEINIT(&ctx, mfrc522_interface_spi_deinit);
|
||||
DRIVER_MFRC522_LINK_SPI_READ(&ctx, mfrc522_interface_spi_read);
|
||||
DRIVER_MFRC522_LINK_SPI_WRITE(&ctx, mfrc522_interface_spi_write);
|
||||
DRIVER_MFRC522_LINK_DELAY_MS(&ctx, mfrc522_interface_delay_ms);
|
||||
DRIVER_MFRC522_LINK_DEBUG_PRINT(&ctx, mfrc522_interface_debug_print);
|
||||
DRIVER_MFRC522_LINK_RECEIVE_CALLBACK(&ctx, mfrc522_interface_receive_callback);
|
||||
|
||||
mfrc522_set_interface(&ctx, MFRC522_INTERFACE_SPI);
|
||||
uint8_t init_retval = mfrc522_init(&ctx);
|
||||
|
||||
if (init_retval != 0) {
|
||||
mfrc522_interface_debug_print("ERR: %s failed: %d\n", __FUNCTION__, init_retval);
|
||||
}
|
||||
|
||||
// Set IRQ pin of MFRC522 to CMOS, enable irq on pico on success
|
||||
uint8_t irq_pin_type_ret = mfrc522_set_interrupt_pin_type(&ctx, MFRC522_INTERRUPT_PIN_TYPE_STANDARD_CMOS);
|
||||
if (irq_pin_type_ret != 0) {
|
||||
mfrc522_interface_debug_print("ERR: Could not set interrupt pin type.\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
mfrc522_integration_irq_init(&ctx);
|
||||
}
|
||||
|
||||
// replicate arduino behavior
|
||||
setup_attempt_2();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
||||
Reference in New Issue
Block a user