Part Number: MSP430F5528
Board: MSP430G2ET + TRF7090A RFID Boosterpack
System: Windows 10 Enterprise x64
Im writing a Python script on windows which wants to read out the UID over the serial connection.
I want to loop this endlessly but my programm stops at about 23 ser.reads.
My guess is that some kind of transmit or receive buffer is filling with each call and that it needs to get a reset after each successful readout.
The amount of calls at which the programm stops is consistent. Therefore i dont think its a problem related to some time.sleep problems.
Thanks in advance for your help. WIth kind regards.
import serial.tools.list_ports
import time
ns_val = time.time_ns()
serPort = ""
int1 = 0
str1 = ""
str2 = ""
ports = list(serial.tools.list_ports.comports())
for p in ports:
print(p) # This causes each port's information to be printed out.
# To search this p data, use p[1].
while int1 < 20: # Loop checks "COM0" to "COM8" for Msp Port Info.
if "UART1" in p[1]: # Looks for "UART1" in P[1].
str2 = str(int1) # Converts an Integer to a String, allowing:
str1 = "COM" + str2 # add the strings together.
if "UART1" in p[1] and str1 in p[1]: # Looks for "Msp" and "COM#"
print("Found MSP430 on %s" % (str1))
int1 = 20 # Causes loop to end.
if int1 == 19:
print("MSP not found!")
int1 = int1 + 1
int1 = 0
# Set Port
ser = serial.Serial(str1, 9600, bytesize=serial.EIGHTBITS) # Put in your speed and timeout value.
ser.close()
ns_ports = time.time_ns()
# get UID from UART
data1 = ""
ser.close()
ser.open()
ser.write('0'.encode())
buffer = ser.readline()
UID = ser.readline().decode('UTF-8')
UID = UID.replace("\n", "") # replace \n so we don't have a paragraph
print("NFC UID: ",UID)
ser.close()
ns_uid = time.time_ns()
time_needed_for_port_init = (((ns_ports - ns_val)/1000000)/1000)
time_needed_for_read_uid = (((ns_uid - ns_ports)/1000000)/1000)
print("Time port init: ",time_needed_for_port_init)
print("Time read uid: ",time_needed_for_read_uid)
#include "nfc_app.h"
#include "trf79xxa.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "clock.h"
void Send_UID(void)
{
uint8_t ui8LoopCount = 0;
for (ui8LoopCount = 0; ui8LoopCount < 8; ui8LoopCount++) //8 Byte UID. Po Schleifendurchlauf 1 Byte an Host gesendet
{
UART_putByte(g_pui8Iso15693UId[7-ui8LoopCount]); // Send UID to host
}
UART_putNewLine(); //nachdem die UID gesendet wurde wird eine leere Zeile gesendet (zur Übersichtlichkeit)
}
void main(void)
{
uint8_t ui8VLOCalibCount = 0;
// TODO: Remove LED2 Jumper on G2 LaunchPad if using it, otherwise SPI will not work.
// Stop the Watchdog timer,
WDTCTL = WDTPW + WDTHOLD;
P1DIR |= BIT0;
P1OUT &= ~BIT0;
// 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_5V_FULL_POWER);
#ifdef ENABLE_HOST
// Set up UART
UART_setup();
IE2 |= UCA0RXIE;
_BIS_SR(GIE);
#endif
// Initialize all enabled technology layers
NFC_init();
// Enable global interrupts
__bis_SR_register(GIE);
__enable_interrupt();
// Enable IRQ Pin
IRQ_ON;
#ifdef ENABLE_HOST
// UART_putIntroReaderMsg();
#endif
TRF79xxA_setupInitiator(0x02);
// The VCD should wait at least 1 ms after it activated the
// powering field before sending the first request, to
while(1)
{
UART_putNewLine();
Change_Protect_Status = true;
New_Password = true;
Write_Data = true;
Reset_Data = true;
askdiff = true;
uint8_t ui8LoopCount = 0; // ensure that the VICCs are ready to receive it. (ISO15693-3)
MCU_delayMillisecond(100);
ISO15693_resetTagCount();
ISO15693_SingleInventory();
Send_UID();
MCU_delayMillisecond(20);
while(UART_Not_Recieved)
{
}
UART_Not_Recieved = true;
if(RX== '1') //Read all datablocks
{
UART_putNewLine();
My_sendReadMultipleBlocks(0x22, 0, 42);
MCU_delayMillisecond(80);
My_sendReadMultipleBlocks(0x22, 42, 11);
}
for (ui8LoopCount = 0; ui8LoopCount < 8; ui8LoopCount++)
{
g_pui8Iso15693UId[ui8LoopCount] = 0; // Send UID to host
}
// 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;
}
}
}