text: After recognising having more than 4 days, I took a deep breath and heading to the working prototype. In the previous article, I have made a simple gate control. In this week I made some additional functionality and will demonstrate it on the video. The idea of this part is not allowing the miner to access mining area without the helmet (or can be any safety clothes) so providing the safety. It also records the access control which makes managing and planning easier.
  The system is consist of NFC reader and NFC tag. In reality, short range RFDI system will be suitable hence NFC allows a few cms which is very short distance. However, the implementation of the system and how it works is completely the same.
  Let's see how system works
  I have used the example code here (DLP-7970ABP NFC Transceiver Booster Pack | TI.com ). I made some change on the program. First, RX is not activated by the example code so I need to enable the RX pin to send the gate to open command.
  // Modified code P1SEL |= BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD P1SEL2 |= BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD // The original Code //P1SEL |= BIT2; // P1.2=TXD //P1SEL2 |= BIT2; // P1.2=TXD
  After enabling RX, I implemented RX data received interrupt. Therefore, I need to activate the RX interrupt.
  UC0IE |= UCA0RXIE; // Enable USCI_A0 RX interrupt
  Then interrupt service routine to open the gate.
  #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { if (UCA0RXBUF == '1') // '1' received? open the gate { P1OUT |= 1; delay_ms(5000); P1OUT &= 0xfe; } else //Gate is closed { P1OUT &= 0xfe; // Not necessary for the current program } }
  In the interrupt service routine program gets the information from the Ground Operations Centre. Ground Operations Centre checks whether this user is inside (it may be fake ID or user throw the helmet back ) or the ID is valid. If the user is allowed to access, it sends "1" to gate control board. If "1" is gotten by the gate control board, it will turn on the LED (open the gate), waits 5 seconds while disabling reading activities and then turn off the LED (close the gate). Using delay inside the interrupt is a terrible idea but in this time it does what I want.
  Time is running, I will make some changes on the design and shoot videos and demonstrate how the system works.
  You can see all the links related to this project in the first blog: Safe & Sound Wearables - Trackable Safety Helmet for Miners #1: Introduction to Project
  Here is the full code.
  /* * File Name: main.c * * Description:. * * * Copyright (C) 2016 Texas Instruments Incorporated - * * *: * This example detects ISO15693, Type 2, Type 3, Type 4A, Type 4B * NFC/RFID tags. It then indicates the Tag type through LED's on the * TRF7970A Booster pack. Information such as tag UID's and block data is * sent out via a UART at 115200 Baud and can be read on a Computer. * *. * * The TRF7970A is interfaced to a MSP430G2553 through a SPI (serial) * interface using a hardware USCI. The MCU is the master device and * initiates all communication with the reader. * * The anti-collision procedures (as described in the ISO * standards 14443A/B and 15693) are implemented in the MCU * firmware to help the reader detect and communicate with one * PICC/VICC among several PICCs/VICCs. * * AUTHORS: Josh Wyatt * Ralph Jacobi * * BUILT WITH: * Code Composer Studio Core Edition Version: 6.0.1.00040 * (c) Copyright Texas Instruments, 2014. All rights reserved. *****************************************************************/ //=============================================================== // Program with hardware USART and SPI communication ; // interface with TRF7970A reader chip. ; // ; // PORT1.0 - HEART BEAT LED ; // PORT1.1 - UART RX ; // PORT1.2 - UART TX ; // PORT1.5 - SPI DATACLK ; // PORT1.6 - SPI MOSI TODO: Remove LED2 Jumper on G2 LaunchPad ; // PORT1.7 - SPI MISO ; // ; // PORT2.7 - IRQ (INTERUPT REQUEST from TRF7970A) (XOUT on LP) ; // PORT2.1 - SLAVE SELECT ; // PORT2.2 - TRF7970A ENABLE ; // PORT2.3 - ISO14443B LED ; // PORT2.4 - ISO14443A LED ; // PORT2.5 - ISO15693 LED ; //=============================================================== #include "nfc_app.h" #include "trf79xxa.h" #include <string.h> #include <stdbool.h> #include "MSP430.h" // Processor specific header void delay_ms(unsigned int ms) { while (ms) { __delay_cycles(1000); ms--; } } #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { if (UCA0RXBUF == '1') // '1' received? open the gate { P1OUT |= 1; delay_ms(9000); P1OUT &= 0xfe; } else //Gate is closed { P1OUT &= 0xfe; // Not necessary for the current program } } //=============================================================== void main(void) { uint8_t ui8VLOCalibCount; char x; // TODO: Remove LED2 Jumper on G2 LaunchPad if using it, otherwise SPI will not work. // Stop the Watchdog timer, WDTCTL = WDTPW + WDTHOLD; // Select DCO to be 8 MHz MCU_initClock(); MCU_delayMillisecond(10); // Calibrate VLO MCU_calculateVLOFreq(); // Set the SPI SS high SLAVE_SELECT_PORT_SET; SLAVE_SELECT_HIGH; // Four millisecond delay between bringing SS high and then EN high per TRF7970A Datasheet MCU_delayMillisecond(4); // Set TRF Enable Pin high TRF_ENABLE_SET; TRF_ENABLE; // Wait until TRF system clock started MCU_delayMillisecond(5); // Set up TRF initial settings TRF79xxA_initialSettings(); TRF79xxA_setTrfPowerSetting(TRF79xxA_3V_FULL_POWER); #ifdef ENABLE_HOST // Set up UART UART_setup(); #endif // Initialize all enabled technology layers NFC_init(); P1DIR |= 0x1; P1OUT &= 0xfe; UC0IE |= UCA0RXIE; // Enable USCI_A0 RX interrupt // Enable global interrupts __bis_SR_register(GIE); // Enable IRQ Pin IRQ_ON; #ifdef ENABLE_HOST UART_putIntroReaderMsg(RFID_READER_FW_VERSION, RFID_READER_FW_DATE); #endif while(1) { // Poll for NFC tags NFC_findTag(); // VLO drifts with temperature and over time, so it must be periodically recalibrated // Calibrate the VLO every 25 passes of the NFC polling routine ui8VLOCalibCount++; if (ui8VLOCalibCount == 25) { // Calibrate VLO MCU_calculateVLOFreq(); // Reset Calibration Counter ui8VLOCalibCount = 0; } } }