Quantcast
Viewing all articles
Browse latest Browse all 5139

SDK • Re: GPIO Pin configuration Raspberry Pi Pico

Hi,

Thank for your reply. I have done that you have suggested and effectively, it works. The conflictive part of the code has to be here

Code:

int8_t writeCommand(const uint8_t *header, uint8_t hlen){    command = header[0];    pn532_packetbuffer[0] = PN532_PREAMBLE;    pn532_packetbuffer[1] = PN532_STARTCODE1;    pn532_packetbuffer[2] = PN532_STARTCODE2;    uint8_t length = hlen + 1; // LENGTH (TFI+DATA)    pn532_packetbuffer[3] = length;    pn532_packetbuffer[4] = (~length + 1) & 0xFF;    pn532_packetbuffer[5] = PN532_HOSTTOPN532;    uint8_t sum = PN532_HOSTTOPN532;    for (uint8_t i = 0; i < hlen; i++)    {        pn532_packetbuffer[6+i] = header[i];        sum+= header[i];    }    uint8_t checksum = ~sum + 1;    pn532_packetbuffer[6+hlen] = checksum;    pn532_packetbuffer[6+hlen+1] = PN532_POSTAMBLE;    i2c_write_timeout_us(i2c0, _I2C_ADDRESS, &pn532_packetbuffer[0], 8 + hlen, false, PN532_TIMEOUT );    return readAckFrame();}bool readAckFrame(){    uint16_t timeout = 5;    uint8_t ackFrame[] = {0x01,0x00,0x00,0xFF,0x00,0xFF,0x00};    uint16_t time = 0;    uint8_t buff[255];    do {        if (i2c_read_timeout_us(i2c0, _I2C_ADDRESS, &buff[0], sizeof(ackFrame), false, PN532_TIMEOUT)) {            if (buff[0]==0x01) break; // STATUS - Pag. 42 del manual        }        sleep_ms(10); time++;        if ((0 != timeout) && (time > timeout)) return -1;    } while (1);    bool compare = true;    for (int i =0; i< sizeof(ackFrame); i++)    {        if (buff[i] != ackFrame[i])        {            compare = false;        }    }    return compare;}int16_t getResponse(uint8_t *buf, uint16_t timeout) {    const uint8_t PN532_NACK[] = {0, 0, 0xFF, 0xFF, 0, 0};    uint16_t time = 0;    do {        if (i2c_read_timeout_us(i2c0, _I2C_ADDRESS, buf, PN532_FRAME_MAX_LENGTH, false, PN532_TIMEOUT)) {            if (buf[0]==0x01) break; // STATUS - Pag. 42 del manual        }        sleep_ms(10); time++;        if ((0 != timeout) && (time > timeout)) return -1;    } while (1);    uint8_t length = buf[POS_LEN];    return length;
But I cannot concrete more, due to if a remove one of the functions, the PN532 stops the generation of the IRQ pin. However, it has to be one of the i2c functions that I use. It is the only thing that makes sense. Is there any incompatibility of i2c with gpio that i am not taking into account

Best regards and thank you all!

Statistics: Posted by btdgvdn — Sun Apr 28, 2024 10:49 pm



Viewing all articles
Browse latest Browse all 5139

Trending Articles