Hi,
I am using Tiva C - TM4C123G and i am connecting this with the NFC module PN532 through the I2C communication.
The problem that is I can't communicate with the NFC module. I am already tried a lot of approaches to communicate with it but a don't obtain results.
In first step i am trying to get the firmware version of the PN532 module and sending it by the uart port 0.
---------------------------------------------------------------------------------------------------------
My code is:
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"
#include "utils/uartstdio.h"
#define SLAVE_ADDRESS_Write (0x48)
#define SLAVE_ADDRESS_Read (0x49)
//Normal Information Frame
#define Preamble 0x00
#define Startcode1 0x00
#define Startcode2 0xFF
#define LEN 0x02 // --> Number of bytes of TFI and PD0 to PDn
#define LCS 0xFE // --> Lower byte of LEN + LCS = 0x00
#define TFI 0xD4 // --> Identifier D4 or D5
#define PD0 0x02 // --> DATA Getfirmware code 0x02
#define DCS 0x2A // --> Lower byte TFI + PDO = 0x00
#define Posamble 0x00
// Preamble | Startcode1 | Startcode2 | LEN | LCS | TFI | PDO | DCS | Preamble
unsigned char msg;
void
ConfigureUART0(void)
{
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); //80MHZ
//
// Enable the GPIO Peripheral used by the UART.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Enable UART0
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
//
// Configure GPIO Pins for UART mode.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, 16000000);
}
int main ()
{
ConfigureUART0();
UARTprintf("Start program - I2C\n");
ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // 80 MHz
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
ROM_GPIOPinConfigure(GPIO_PA6_I2C1SCL);
ROM_GPIOPinConfigure(GPIO_PA7_I2C1SDA);
ROM_GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
ROM_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
ROM_I2CMasterEnable(I2C1_BASE);
ROM_I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), false);
while (1)
{
ROM_I2CMasterSlaveAddrSet(I2C1_BASE, SLAVE_ADDRESS_Write, false);
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
ROM_I2CMasterDataPut(I2C1_BASE,Preamble);
ROM_I2CMasterDataPut(I2C1_BASE,Startcode1);
ROM_I2CMasterDataPut(I2C1_BASE,Startcode2);
ROM_I2CMasterDataPut(I2C1_BASE,LEN);
ROM_I2CMasterDataPut(I2C1_BASE,LCS);
ROM_I2CMasterDataPut(I2C1_BASE,TFI);
ROM_I2CMasterDataPut(I2C1_BASE,PDO);
ROM_I2CMasterDataPut(I2C1_BASE,DCS);
ROM_I2CMasterDataPut(I2C1_BASE,Posamble);
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_SINGLE_SEND);// sent
while(ROM_I2CMasterBusy(I2C1_BASE));
ROM_I2CMasterSlaveAddrSet(I2C1_BASE, SLAVE_ADDRESS_Read, true);//read mode
ROM_I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
UARTprintf("MSG =\n");
for (int i = 0; i<20; i++){
ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
// msg = ((I2CMasterDataGet(I2C1_BASE) >> 16) & 0xFF);
msg = (I2CMasterDataGet(I2C1_BASE));
UARTprintf(" %02x\n", msg);
}
UARTprintf("---\n");
ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
}
}
-----------------------------------------------------------------------------------------------------------------------------------
In serial port i can read '00' in 3 first readings and after this i only obtain 'ff' until the end of cycle. And i don't know why it happens.
Can you please help me with this?
Best Regards,
Filipe