NFC/RFID Booster Pack with Sharp LCD
Hardware:
SimpleLink MSP432P401R LaunchPad
Software:
TIDM-NFC-RW Near Field Communication (NFC) Reader/Writer Reference Design | TI.com
With my Hearing Guard System one of the features I plan to implement is to enable some sort of NFC to Bluetooth Connection Handover and since the Safe Sound kit came with a DLP-7970ABPDLP-7970ABP Booster Pack it was a good opportunity to see about configuring this I had seen the post by Feng Yao with his Flooding early-warning Alarm Pack project which is a good intro to the DLP-7970ABPDLP-7970ABP however in my project I want to implement NFC/RFID along with Bluetooth and the Sharp LCD but neither the 430BOOST-SHARP96430BOOST-SHARP96 LCD nor the DLP-7970ABPDLP-7970ABP Booster Pack have stackable headers So basically you can only have one other the other on the MSP432 at a time To resolve this I changed some of the GPIO assignments for the DLP-7970ABPDLP-7970ABP in the NFC example and was able to hack through the code to get some of the NFC data to display on the Sharp LCD
The example I used was the P401R_TRF7970A_ALL_NFC_MODES that was installed through the TIDM-NFC-RW Software (Rev. A) reference design:
http://www.ti.com/tool/TIDM-NFC-RW
The example is mainly for the MSP430F5529 USB microcontroller development kit, but there is some basic support for the MSP432. However, since the MSP430F5529 has an LCD, the code in the NFC-RW example can be used for the Sharp LCD with some code modifications.
After importing the example project into Code Composer Studio, add the grlib and LcdDriver folders to the project as outlined in Jan Cumps post.
In order to get both the DLP-7970ABPDLP-7970ABP and Sharp LCD Booster Pack to simultaneously on the MSP432 I moved the non SPI connections for the DLP-7970ABPDLP-7970ABP to the inner headers on the MSP432 The basic SPI connections do not need to change but I did use a separate GPIO for the slave select
With the GPIO pins to use for the NFC/RFID Booster pack, edit the 'config.h' in the project 'config' folder.
The code change that I implemented in the config.h looks like this:
NOTE: The values in the comments are the before values.
// // TRF79790A Hardware Configuration // #define SPI_MODULE_BASE_ADDR EUSCI_B0_MODULE #define SPI_PORT GPIO_PORT_P1 #define SPI_CLK GPIO_PIN5 #define SPI_MOSI GPIO_PIN6 #define SPI_MISO GPIO_PIN7 #define SPI_SS_PORT GPIO_PORT_P5 // GPIO_PORT_P6 #define SPI_SS_POUT P5OUT // P6OUT #define SPI_SS GPIO_PIN4 // GPIO_PIN5 #define TRF_EN_PORT GPIO_PORT_P5 // GPIO_PORT_P6 #define TRF_EN GPIO_PIN5 // GPIO_PIN4 #define TRF_IRQ_PORT GPIO_PORT_P2 // GPIO_PORT_P3 #define TRF_IRQ_PIN P2IN // P3IN #define TRF_IRQ GPIO_PIN4 // GPIO_PIN0 // // P2.0 - Displays if the external RF field is enabled. // #define NFC_RF_FIELD_LED_BIT BIT0 #define NFC_RF_FIELD_LED_POUT P2OUT #define NFC_RF_FIELD_LED_DIR P2DIR // // P1.0 - Displays if the NFC host is connected to the controller. // #define NFC_HOST_LED_BIT BIT0 #define NFC_HOST_LED_POUT P1OUT #define NFC_HOST_LED_DIR P1DIR // // P - Toggles during the RX of a NDEF packet via P2P. // #define NFC_RX_LED_BIT #define NFC_RX_LED_POUT #define NFC_RX_LED_PDIR // // P - Toggles during the TX of a NDEF packet via P2P. // #define NFC_TX_LED_BIT #define NFC_TX_LED_POUT #define NFC_TX_LED_PDIR // // LED1 P3.6 - Displays if the RW link is established. // #define NFC_RW_LED_BIT BIT7 // BIT6 #define NFC_RW_LED_POUT P3OUT #define NFC_RW_LED_PDIR P3DIR // // LED2 P5.2 - Displays if the CE link is established. // #define NFC_P2P_LED_BIT BIT5 // BIT2 #define NFC_P2P_LED_POUT P3OUT // P5OUT #define NFC_P2P_LED_PDIR P3DIR // P5DIR // // LED3 P5.0 - Displays if the P2P link is established. // #define NFC_CE_LED_BIT BIT1 // BIT0 #define NFC_CE_LED_POUT P5OUT #define NFC_CE_LED_PDIR P5DIR
Next, the Slave Select needs to change to match the values in the config.h file. This can be found in the 'nfc_spi.h' file.
NOTE: Pin 6.5 on the MSP432 is used by the Sharp LCD Booster Pack for one of the Touch Slider inputs.
// Set P6.5 to output direction // Changed to P5.4 for sharp LCD support GPIO_setAsOutputPin( GPIO_PORT_P5, GPIO_PIN4 ); GPIO_setOutputHighOnPin( GPIO_PORT_P5, GPIO_PIN4 );
Now, in the 'main.c', I added a preprocessor directive for the MSP432 LCD to match what was used for the MSP430F5529 device.
#ifdef MSP432P401R_LAUNCHPAD_ENABLED #include "lp_buttons.h" #define MSP432P401R_EXP_LCD_ENABLED 1 #endif
To support the Sharp LCD, reference to the Graphics libs needs to be added.
/* GrLib Includes */ #include "grlib.h" #include <lcddriver/sharp96x96.h.> Graphics_Context g_sContext;
I modified the existing LCD_stringDraw function in the sample code to add support for the MSP432 and Sharp LCD. The function will replace the existing value on the display with a new one without having to refresh the entire screen.
NOTE: I had to add TRF79x0_init() to reenable the NFC Reader after writing to the LCD but I am not sure why at this time.
void LCD_stringDraw(uint8_t row, uint8_t col, char *word, uint8_t style) { int8_t *clearWord = "############"; #ifdef MSP432P401R_EXP_LCD_ENABLED Graphics_Rectangle rect; /* Clear message area */ rect.xMin = col; rect.xMax = Graphics_getDisplayWidth(&g_sContext) - 1; rect.yMin = row; rect.yMax = row + Graphics_getFontHeight(g_sContext.font); Graphics_setForegroundColor(&g_sContext, ClrWhite); Graphics_fillRectangle(&g_sContext, &rect); Graphics_setForegroundColor(&g_sContext, ClrBlack); /* Write new message to bottom of display */ if( word != NULL) { GrContextForegroundSet(&g_sContext, ClrWhite); Graphics_fillRectangle(&g_sContext, &rect); GrContextForegroundSet(&g_sContext, ClrBlack); Graphics_drawString(&g_sContext, (int8_t *)(word), GRAPHICS_AUTO_STRING_LENGTH, rect.xMin, rect.yMin, GRAPHICS_TRANSPARENT_TEXT); } GrFlush(&g_sContext); #endif #ifdef MSP430F5529_EXP_LCD_ENABLED Dogs102x6_stringDraw(row,col,word,style); #endif TRF79x0_init(); }
To initialize the Sharp LCD, I added a Sharp_LCD_init() function and I added a LCD_printMessage() to display the main NFC display.
void LCD_printMessage(void) { GrClearDisplay(&g_sContext); //GrContextFontSet(&g_sContext, &g_sFontCm20b); GrContextFontSet(&g_sContext, &g_sFontFixed6x8); GrStringDraw(&g_sContext, "TRF7970A NFC", -1, 5, 5, 0); GrStringDraw(&g_sContext, "P2P CE RW " , -1, 5, 15, 0); GrStringDraw(&g_sContext, "Ver: ", -1, 5, 25, 0); GrStringDraw(&g_sContext, NFC_FW_VERSION , -1, 30, 25, 0); GrStringDraw(&g_sContext, "Mode : " , -1, 5, 35, 0); GrStringDraw(&g_sContext, "Tech : " , -1, 5, 45, 0); GrStringDraw(&g_sContext, "BITR : " , -1, 5, 55, 0); GrStringDraw(&g_sContext, "RX : " , -1, 5, 65, 0); GrStringDraw(&g_sContext, "RSSI : " , -1, 5, 75, 0); GrFlush(&g_sContext); //Enable interrupts globally TRF79x0_init(); }
In main(), Initialize the Sharp LCD and print the main NFC display to the Sharp LCD.
// If MSP432 has a Sharp LCD enabled, run the Sharp LCD init #ifdef MSP432P401R_EXP_LCD_ENABLED //Sharp_LCD_init(); Sharp_LCD_init(); #endif // Initialize TRF7970 TRF79x0_init(); Buttons_init(BUTTON_ALL); Buttons_interruptEnable(BUTTON_ALL); TRF79x0_idleMode(); // Initialize the NFC Controller NFC_init(); // This function will configure all the settings for each protocol NFC_configuration(); // Initialize Type 4 Tag RTD Message T4T_CE_initNDEF(); // Initialize IDs for NFC-A, NFC-B and NFC-F NFC_initIDs(); #ifdef MSP432P401R_EXP_LCD_ENABLED LCD_printMessage(); #endif
The main() function is a bit long and contains many '#ifdef' entries, but one that I found that is useful is to print the number of Bytes Received.
#if (NFC_PEER_2_PEER_INITIATOR_ENABLED || NFC_PEER_2_PEER_TARGET_ENABLED) if(eCurrentNFCState == NFC_DATA_EXCHANGE_PROTOCOL) // JM NFC Reaches here { updateLcdfcStatus(false); #ifdef MSP430F5529_EXP_LCD_ENABLED convertWordToAscii(ui16BytesReceived,(uint8_t *)pcBytesReceivedString); LCD_stringDraw(6,11*6,pcBytesReceivedString,DOGS102x6_DRAW_NORMAL); #endif #ifdef MSP432P401R_EXP_LCD_ENABLED convertWordToAscii(ui16BytesReceived,(uint8_t *)pcBytesReceivedString); LCD_stringDraw(65,57,pcBytesReceivedString,DOGS102x6_DRAW_NORMAL); #endif
Also, in the updateLcdfcStatus() function. the RSSI (Received Signal Strength Indicator) is set and can be used to send to the Sharp LCD.
This is a good indicator to show the signal strength received when a NFC tag is presented.
NOTE: This is shown in the video shown later in the post.
if(eTrfStatus.ui8InternalRssi != ui8RssiValue) // JM NFC Reaches here { ui8RssiValue = eTrfStatus.ui8InternalRssi; convertByteToAscii(eTrfStatus.ui8InternalRssi,(uint8_t *)pui8Buffer); #ifdef MSP430F5529_EXP_LCD_ENABLED LCD_stringDraw(7,11*6,pui8Buffer,DOGS102x6_DRAW_NORMAL); #endif #ifdef MSP432P401R_EXP_LCD_ENABLED LCD_stringDraw(75,57,pui8Buffer,DOGS102x6_DRAW_NORMAL); #endif
So that is what I have enabled thus far and if I have not forgotten anything this is all that is need to enable the Sharp LCD connected to the MSP432 with the DLP-7970ABPDLP-7970ABP booster pack
Here is a video showing the DLP-7970ABPDLP-7970ABP and 430BOOST-SHARP96430BOOST-SHARP96 working on the MSP432 LaunchPad