Arduino RC 522 write and read data - arduino

I'm working on Arduino RC 522 RFID module. I'm want to write some data in the RFID card and read that data to operate a relay. So is that possible? I want to store integer data in the RFID CARD(13.5Mhz).

for writing the card you can try with this code, change the variable "blockData" with the integer, the lenght should be 16 bytes or you have to change the dimensions of the arrays and for cycles.
#include <SPI.h>
#include <MFRC522.h>
/*Using Hardware SPI of Arduino */
/*MOSI (11), MISO (12) and SCK (13) are fixed */
/*You can configure SS and RST Pins*/
#define SS_PIN 10 /* Slave Select Pin */
#define RST_PIN 7 /* Reset Pin */
/* Create an instance of MFRC522 */
MFRC522 mfrc522(SS_PIN, RST_PIN);
/* Create an instance of MIFARE_Key */
MFRC522::MIFARE_Key key;
/* Set the block to which we want to write data */
/* Be aware of Sector Trailer Blocks */
int blockNum = 2;
/* Create an array of 16 Bytes and fill it with data */
/* This is the actual data which is going to be written into the card */
byte blockData [16] = {"Electronics-Hub-"};
/* Create another array to read data from Block */
/* Legthn of buffer should be 2 Bytes more than the size of Block (16 Bytes) */
byte bufferLen = 18;
byte readBlockData[18];
MFRC522::StatusCode status;
void setup()
{
/* Initialize serial communications with the PC */
Serial.begin(9600);
/* Initialize SPI bus */
SPI.begin();
/* Initialize MFRC522 Module */
mfrc522.PCD_Init();
Serial.println("Scan a MIFARE 1K Tag to write data...");
}
void loop()
{
/* Prepare the ksy for authentication */
/* All keys are set to FFFFFFFFFFFFh at chip delivery from the factory */
for (byte i = 0; i < 6; i++)
{
key.keyByte[i] = 0xFF;
}
/* Look for new cards */
/* Reset the loop if no new card is present on RC522 Reader */
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
/* Select one of the cards */
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
Serial.print("\n");
Serial.println("**Card Detected**");
/* Print UID of the Card */
Serial.print(F("Card UID:"));
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.print("\n");
/* Print type of card (for example, MIFARE 1K) */
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
/* Call 'WriteDataToBlock' function, which will write data to the block */
Serial.print("\n");
Serial.println("Writing to Data Block...");
WriteDataToBlock(blockNum, blockData);
/* Read data from the same block */
Serial.print("\n");
Serial.println("Reading from Data Block...");
ReadDataFromBlock(blockNum, readBlockData);
/* If you want to print the full memory dump, uncomment the next line */
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
/* Print the data read from block */
Serial.print("\n");
Serial.print("Data in Block:");
Serial.print(blockNum);
Serial.print(" --> ");
for (int j=0 ; j<16 ; j++)
{
Serial.write(readBlockData[j]);
}
Serial.print("\n");
}
void WriteDataToBlock(int blockNum, byte blockData[])
{
/* Authenticating the desired data block for write access using Key A */
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK)
{
Serial.print("Authentication failed for Write: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Authentication success");
}
/* Write data to the block */
status = mfrc522.MIFARE_Write(blockNum, blockData, 16);
if (status != MFRC522::STATUS_OK)
{
Serial.print("Writing to Block failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Data was written into Block successfully");
}
}
void ReadDataFromBlock(int blockNum, byte readBlockData[])
{
/* Authenticating the desired data block for Read access using Key A */
byte status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK)
{
Serial.print("Authentication failed for Read: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Authentication success");
}
/* Reading data from the Block */
status = mfrc522.MIFARE_Read(blockNum, readBlockData, &bufferLen);
if (status != MFRC522::STATUS_OK)
{
Serial.print("Reading failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Block was read successfully");
}
}
For reading data use this code, change "mioCod" with the UID of the card
void ceckRFID(){
//check new cards
if (!mfrc522.PICC_IsNewCardPresent())
{
return;
}
//If read UID
if (!mfrc522.PICC_ReadCardSerial())
{
return;
}
String codLetto = ""; //clean the reading string
for (byte i = 0; i < mfrc522.uid.size; i++) { //save the code into the string
codLetto += String(mfrc522.uid.uidByte[i], HEX);
}
codLetto.toUpperCase(); //uppercase the string
Serial.println(codLetto); //print the code
if(codLetto == mioCod){ //if the code match with mioCod
Serial.println("Code recognized");
}
else{
Serial.println("Wrong code");
}
}

Related

Arduino mega with L298n and Motors with Encoders not registering encoders

I am trying to follow a tutorial from youtube on using ROS with Arduino to control motors, and I have connected my L298N with the battery precisely as the video describes and have uploaded sketch 1 with the supporting folder and it loads properly. The Arduino is powered properly via USB, but that connection is not shown in the diagram. When I type the "e" command, I get the proper response of "0 0" and when I do the "o 255 255" it says "OK" and drives properly but upon using "e" to recheck the encoders I am getting the same "0 0". If anyone can spot something wrong with this, I would really appreciate the help in fixing it. Diagram and Code Below
Code:
#define USE_BASE // Enable the base controller code
//#undef USE_BASE // Disable the base controller code
/* Define the motor controller and encoder library you are using */
#ifdef USE_BASE
/* The Pololu VNH5019 dual motor driver shield */
//#define POLOLU_VNH5019
/* The Pololu MC33926 dual motor driver shield */
//#define POLOLU_MC33926
/* The RoboGaia encoder shield */
//#define ROBOGAIA
/* Encoders directly attached to Arduino board */
#define ARDUINO_ENC_COUNTER
/* L298 Motor driver*/
#define L298_MOTOR_DRIVER
#endif
//#define USE_SERVOS // Enable use of PWM servos as defined in servos.h
#undef USE_SERVOS // Disable use of PWM servos
/* Serial port baud rate */
#define BAUDRATE 57600
/* Maximum PWM signal */
#define MAX_PWM 255
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
/* Include definition of serial commands */
#include "commands.h"
/* Sensor functions */
#include "sensors.h"
/* Include servo support if required */
#ifdef USE_SERVOS
#include <Servo.h>
#include "servos.h"
#endif
#ifdef USE_BASE
/* Motor driver function definitions */
#include "motor_driver.h"
/* Encoder driver function definitions */
#include "encoder_driver.h"
/* PID parameters and functions */
#include "diff_controller.h"
/* Run the PID loop at 30 times per second */
#define PID_RATE 30 // Hz
/* Convert the rate into an interval */
const int PID_INTERVAL = 1000 / PID_RATE;
/* Track the next time we make a PID calculation */
unsigned long nextPID = PID_INTERVAL;
/* Stop the robot if it hasn't received a movement command
in this number of milliseconds */
#define AUTO_STOP_INTERVAL 2000
long lastMotorCommand = AUTO_STOP_INTERVAL;
#endif
/* Variable initialization */
// A pair of varibles to help parse serial commands (thanks Fergs)
int arg = 0;
int index = 0;
// Variable to hold an input character
char chr;
// Variable to hold the current single-character command
char cmd;
// Character arrays to hold the first and second arguments
char argv1[16];
char argv2[16];
// The arguments converted to integers
long arg1;
long arg2;
/* Clear the current command parameters */
void resetCommand() {
cmd = NULL;
memset(argv1, 0, sizeof(argv1));
memset(argv2, 0, sizeof(argv2));
arg1 = 0;
arg2 = 0;
arg = 0;
index = 0;
}
/* Run a command. Commands are defined in commands.h */
int runCommand() {
int i = 0;
char *p = argv1;
char *str;
int pid_args[4];
arg1 = atoi(argv1);
arg2 = atoi(argv2);
switch(cmd) {
case GET_BAUDRATE:
Serial.println(BAUDRATE);
break;
case ANALOG_READ:
Serial.println(analogRead(arg1));
break;
case DIGITAL_READ:
Serial.println(digitalRead(arg1));
break;
case ANALOG_WRITE:
analogWrite(arg1, arg2);
Serial.println("OK");
break;
case DIGITAL_WRITE:
if (arg2 == 0) digitalWrite(arg1, LOW);
else if (arg2 == 1) digitalWrite(arg1, HIGH);
Serial.println("OK");
break;
case PIN_MODE:
if (arg2 == 0) pinMode(arg1, INPUT);
else if (arg2 == 1) pinMode(arg1, OUTPUT);
Serial.println("OK");
break;
case PING:
Serial.println(Ping(arg1));
break;
#ifdef USE_SERVOS
case SERVO_WRITE:
servos[arg1].setTargetPosition(arg2);
Serial.println("OK");
break;
case SERVO_READ:
Serial.println(servos[arg1].getServo().read());
break;
#endif
#ifdef USE_BASE
case READ_ENCODERS:
Serial.print(readEncoder(LEFT));
Serial.print(" ");
Serial.println(readEncoder(RIGHT));
break;
case RESET_ENCODERS:
resetEncoders();
resetPID();
Serial.println("OK");
break;
case MOTOR_SPEEDS:
/* Reset the auto stop timer */
lastMotorCommand = millis();
if (arg1 == 0 && arg2 == 0) {
setMotorSpeeds(0, 0);
resetPID();
moving = 0;
}
else moving = 1;
leftPID.TargetTicksPerFrame = arg1;
rightPID.TargetTicksPerFrame = arg2;
Serial.println("OK");
break;
case MOTOR_RAW_PWM:
/* Reset the auto stop timer */
lastMotorCommand = millis();
resetPID();
moving = 0; // Sneaky way to temporarily disable the PID
setMotorSpeeds(arg1, arg2);
Serial.println("OK");
break;
case UPDATE_PID:
while ((str = strtok_r(p, ":", &p)) != '\0') {
pid_args[i] = atoi(str);
i++;
}
Kp = pid_args[0];
Kd = pid_args[1];
Ki = pid_args[2];
Ko = pid_args[3];
Serial.println("OK");
break;
#endif
default:
Serial.println("Invalid Command");
break;
}
}
/* Setup function--runs once at startup. */
void setup() {
Serial.begin(BAUDRATE);
// Initialize the motor controller if used */
#ifdef USE_BASE
#ifdef ARDUINO_ENC_COUNTER
//set as inputs
DDRD &= ~(1<<LEFT_ENC_PIN_A);
DDRD &= ~(1<<LEFT_ENC_PIN_B);
DDRC &= ~(1<<RIGHT_ENC_PIN_A);
DDRC &= ~(1<<RIGHT_ENC_PIN_B);
//enable pull up resistors
PORTD |= (1<<LEFT_ENC_PIN_A);
PORTD |= (1<<LEFT_ENC_PIN_B);
PORTC |= (1<<RIGHT_ENC_PIN_A);
PORTC |= (1<<RIGHT_ENC_PIN_B);
// tell pin change mask to listen to left encoder pins
PCMSK2 |= (1 << LEFT_ENC_PIN_A)|(1 << LEFT_ENC_PIN_B);
// tell pin change mask to listen to right encoder pins
PCMSK1 |= (1 << RIGHT_ENC_PIN_A)|(1 << RIGHT_ENC_PIN_B);
// enable PCINT1 and PCINT2 interrupt in the general interrupt mask
PCICR |= (1 << PCIE1) | (1 << PCIE2);
#endif
initMotorController();
resetPID();
#endif
/* Attach servos if used */
#ifdef USE_SERVOS
int i;
for (i = 0; i < N_SERVOS; i++) {
servos[i].initServo(
servoPins[i],
stepDelay[i],
servoInitPosition[i]);
}
#endif
}
/* Enter the main loop. Read and parse input from the serial port
and run any valid commands. Run a PID calculation at the target
interval and check for auto-stop conditions.
*/
void loop() {
while (Serial.available() > 0) {
// Read the next character
chr = Serial.read();
// Terminate a command with a CR
if (chr == 13) {
if (arg == 1) argv1[index] = NULL;
else if (arg == 2) argv2[index] = NULL;
runCommand();
resetCommand();
}
// Use spaces to delimit parts of the command
else if (chr == ' ') {
// Step through the arguments
if (arg == 0) arg = 1;
else if (arg == 1) {
argv1[index] = NULL;
arg = 2;
index = 0;
}
continue;
}
else {
if (arg == 0) {
// The first arg is the single-letter command
cmd = chr;
}
else if (arg == 1) {
// Subsequent arguments can be more than one character
argv1[index] = chr;
index++;
}
else if (arg == 2) {
argv2[index] = chr;
index++;
}
}
}
// If we are using base control, run a PID calculation at the appropriate intervals
#ifdef USE_BASE
if (millis() > nextPID) {
updatePID();
nextPID += PID_INTERVAL;
}
// Check to see if we have exceeded the auto-stop interval
if ((millis() - lastMotorCommand) > AUTO_STOP_INTERVAL) {;
setMotorSpeeds(0, 0);
moving = 0;
}
#endif
// Sweep servos
#ifdef USE_SERVOS
int i;
for (i = 0; i < N_SERVOS; i++) {
servos[i].doSweep();
}
#endif
}
Encoder Pin Designations:
/* *************************************************************
Encoder driver function definitions - by James Nugen
************************************************************ */
#ifdef ARDUINO_ENC_COUNTER
//below can be changed, but should be PORTD pins;
//otherwise additional changes in the code are required
#define LEFT_ENC_PIN_A PD2 //pin 2
#define LEFT_ENC_PIN_B PD3 //pin 3
//below can be changed, but should be PORTC pins
#define RIGHT_ENC_PIN_A PC4 //pin A4
#define RIGHT_ENC_PIN_B PC5 //pin A5
#endif
long readEncoder(int i);
void resetEncoder(int i);
void resetEncoders();
Encoder Driver:
/* *************************************************************
Encoder definitions
Add an "#ifdef" block to this file to include support for
a particular encoder board or library. Then add the appropriate
#define near the top of the main ROSArduinoBridge.ino file.
************************************************************ */
#ifdef USE_BASE
#ifdef ROBOGAIA
/* The Robogaia Mega Encoder shield */
#include "MegaEncoderCounter.h"
/* Create the encoder shield object */
MegaEncoderCounter encoders = MegaEncoderCounter(4); // Initializes the Mega Encoder Counter in the 4X Count mode
/* Wrap the encoder reading function */
long readEncoder(int i) {
if (i == LEFT) return encoders.YAxisGetCount();
else return encoders.XAxisGetCount();
}
/* Wrap the encoder reset function */
void resetEncoder(int i) {
if (i == LEFT) return encoders.YAxisReset();
else return encoders.XAxisReset();
}
#elif defined(ARDUINO_ENC_COUNTER)
volatile long left_enc_pos = 0L;
volatile long right_enc_pos = 0L;
static const int8_t ENC_STATES [] = {0,1,-1,0,-1,0,0,1,1,0,0,-1,0,-1,1,0}; //encoder lookup table
/* Interrupt routine for LEFT encoder, taking care of actual counting */
ISR (PCINT2_vect){
static uint8_t enc_last=0;
enc_last <<=2; //shift previous state two places
enc_last |= (PIND & (3 << 2)) >> 2; //read the current state into lowest 2 bits
left_enc_pos += ENC_STATES[(enc_last & 0x0f)];
}
/* Interrupt routine for RIGHT encoder, taking care of actual counting */
ISR (PCINT1_vect){
static uint8_t enc_last=0;
enc_last <<=2; //shift previous state two places
enc_last |= (PINC & (3 << 4)) >> 4; //read the current state into lowest 2 bits
right_enc_pos += ENC_STATES[(enc_last & 0x0f)];
}
/* Wrap the encoder reading function */
long readEncoder(int i) {
if (i == LEFT) return left_enc_pos;
else return right_enc_pos;
}
/* Wrap the encoder reset function */
void resetEncoder(int i) {
if (i == LEFT){
left_enc_pos=0L;
return;
} else {
right_enc_pos=0L;
return;
}
}
#else
#error A encoder driver must be selected!
#endif
/* Wrap the encoder reset function */
void resetEncoders() {
resetEncoder(LEFT);
resetEncoder(RIGHT);
}
#endif
I think if you use a Mega instead of an Uno, the pin ports are different.
So change the port from PD4 to PE4 and PD3 to PE5. Also, change PC4 to PF4 and PC5 to PF5.
In the Encoder.ino, you also have to change the ports accordingly.
Encoder.h:
#define LEFT_ENC_PIN_A PE4 //pin 2
#define LEFT_ENC_PIN_B PE5 //pin 3
//below can be changed, but should be PORTC pins
#define RIGHT_ENC_PIN_A PF5 //pin A4
#define RIGHT_ENC_PIN_B PF5 //pin A5
Encoder.ino:
/* Interrupt routine for LEFT encoder, taking care of actual counting */
ISR (PCINT2_vect){
static uint8_t enc_last=0;
enc_last <<=2; //shift previous state two places
enc_last |= (PINE & (3 << 2)) >> 2; //read the current state into lowest 2 bits
left_enc_pos += ENC_STATES[(enc_last & 0x0f)];
}
/* Interrupt routine for RIGHT encoder, taking care of actual counting */
ISR (PCINT1_vect){
static uint8_t enc_last=0;
enc_last <<=2; //shift previous state two places
enc_last |= (PINF & (3 << 4)) >> 4; //read the current state into lowest 2 bits
right_enc_pos += ENC_STATES[(enc_last & 0x0f)];
}

How can i write a long string to a RFID tag using arduino?

Hey i would like to write a long string like "Hello my name is james and i live in NewYork" in a rfid Tag using arduino.
The code for writing in a single block is the following one but i can only write 16 bytes in 1 block ....
but the only issue is that it does only write into 1 block.
So i would like that 16 First bytes goes to Block 1 ect ...
#include <SPI.h>
#include <MFRC522.h>
/*Using Hardware SPI of Arduino */
/*MOSI (11), MISO (12) and SCK (13) are fixed */
/*You can configure SS and RST Pins*/
#define SS_PIN 10 /* Slave Select Pin */
#define RST_PIN 7 /* Reset Pin */
/* Create an instance of MFRC522 */
MFRC522 mfrc522(SS_PIN, RST_PIN);
/* Create an instance of MIFARE_Key */
MFRC522::MIFARE_Key key;
/* Set the block to which we want to write data */
/* Be aware of Sector Trailer Blocks */
int blockNum = 2;
/* Create an array of 16 Bytes and fill it with data */
/* This is the actual data which is going to be written into the card */
byte blockData [16] = {"data-to-write-to-card"};
/* Create another array to read data from Block */
/* Legthn of buffer should be 2 Bytes more than the size of Block (16 Bytes) */
byte bufferLen = 18;
byte readBlockData[18];
MFRC522::StatusCode status;
void setup()
{
/* Initialize serial communications with the PC */
Serial.begin(9600);
/* Initialize SPI bus */
SPI.begin();
/* Initialize MFRC522 Module */
mfrc522.PCD_Init();
Serial.println("Scan a MIFARE 1K Tag to write data...");
}
void loop()
{
/* Prepare the ksy for authentication */
/* All keys are set to FFFFFFFFFFFFh at chip delivery from the factory */
for (byte i = 0; i < 6; i++)
{
key.keyByte[i] = 0xFF;
}
/* Look for new cards */
/* Reset the loop if no new card is present on RC522 Reader */
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
/* Select one of the cards */
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
Serial.print("\n");
Serial.println("**Card Detected**");
/* Print UID of the Card */
Serial.print(F("Card UID:"));
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.print("\n");
/* Print type of card (for example, MIFARE 1K) */
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
/* Call 'WriteDataToBlock' function, which will write data to the block */
Serial.print("\n");
Serial.println("Writing to Data Block...");
WriteDataToBlock(blockNum, blockData);
/* Read data from the same block */
Serial.print("\n");
Serial.println("Reading from Data Block...");
ReadDataFromBlock(blockNum, readBlockData);
/* If you want to print the full memory dump, uncomment the next line */
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
/* Print the data read from block */
Serial.print("\n");
Serial.print("Data in Block:");
Serial.print(blockNum);
Serial.print(" --> ");
for (int j=0 ; j<16 ; j++)
{
Serial.write(readBlockData[j]);
}
Serial.print("\n");
}
void WriteDataToBlock(int blockNum, byte blockData[])
{
/* Authenticating the desired data block for write access using Key A */
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK)
{
Serial.print("Authentication failed for Write: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Authentication success");
}
/* Write data to the block */
status = mfrc522.MIFARE_Write(blockNum, blockData, 16);
if (status != MFRC522::STATUS_OK)
{
Serial.print("Writing to Block failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Data was written into Block successfully");
}
}
void ReadDataFromBlock(int blockNum, byte readBlockData[])
{
/* Authenticating the desired data block for Read access using Key A */
byte status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK)
{
Serial.print("Authentication failed for Read: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Authentication success");
}
/* Reading data from the Block */
status = mfrc522.MIFARE_Read(blockNum, readBlockData, &bufferLen);
if (status != MFRC522::STATUS_OK)
{
Serial.print("Reading failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Block was read successfully");
}

How can I write personal data on a RFID sensor in arduino in my code?

I want to write a personal data on my Card like:
"Name"
"Age"
"Region"
etc.
I wanna do this in this code:
https://imgur.com/BnlsKU3
https://imgur.com/4lNDqVX
https://imgur.com/LGCdXET
On this links are my screens to my code
Use this basic approach to adapt to your code. So far your arduino code is only reading information from the card or tag with pre-loaded data.
You can follow this to write data to your card
Pls: Follow your card documentation or datasheet on the amount of data you can write to it
#include <SPI.h>
#include <MFRC522.h>
/*Using Hardware SPI of Arduino */
/*MOSI (11), MISO (12) and SCK (13) are fixed */
/*You can configure SS and RST Pins*/
#define SS_PIN 10 /* Slave Select Pin */
#define RST_PIN 7 /* Reset Pin */
/* Create an instance of MFRC522 */
MFRC522 mfrc522(SS_PIN, RST_PIN);
/* Create an instance of MIFARE_Key */
MFRC522::MIFARE_Key key;
/* Set the block to which we want to write data */
/* Be aware of Sector Trailer Blocks */
int blockNum = 2;
/* Create an array of 16 Bytes and fill it with data */
/* This is the actual data which is going to be written into the card */
byte blockData [16] = {"data-to-write-to-card"};
/* Create another array to read data from Block */
/* Legthn of buffer should be 2 Bytes more than the size of Block (16 Bytes) */
byte bufferLen = 18;
byte readBlockData[18];
MFRC522::StatusCode status;
void setup()
{
/* Initialize serial communications with the PC */
Serial.begin(9600);
/* Initialize SPI bus */
SPI.begin();
/* Initialize MFRC522 Module */
mfrc522.PCD_Init();
Serial.println("Scan a MIFARE 1K Tag to write data...");
}
void loop()
{
/* Prepare the ksy for authentication */
/* All keys are set to FFFFFFFFFFFFh at chip delivery from the factory */
for (byte i = 0; i < 6; i++)
{
key.keyByte[i] = 0xFF;
}
/* Look for new cards */
/* Reset the loop if no new card is present on RC522 Reader */
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
/* Select one of the cards */
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
Serial.print("\n");
Serial.println("**Card Detected**");
/* Print UID of the Card */
Serial.print(F("Card UID:"));
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.print("\n");
/* Print type of card (for example, MIFARE 1K) */
Serial.print(F("PICC type: "));
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
Serial.println(mfrc522.PICC_GetTypeName(piccType));
/* Call 'WriteDataToBlock' function, which will write data to the block */
Serial.print("\n");
Serial.println("Writing to Data Block...");
WriteDataToBlock(blockNum, blockData);
/* Read data from the same block */
Serial.print("\n");
Serial.println("Reading from Data Block...");
ReadDataFromBlock(blockNum, readBlockData);
/* If you want to print the full memory dump, uncomment the next line */
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
/* Print the data read from block */
Serial.print("\n");
Serial.print("Data in Block:");
Serial.print(blockNum);
Serial.print(" --> ");
for (int j=0 ; j<16 ; j++)
{
Serial.write(readBlockData[j]);
}
Serial.print("\n");
}
void WriteDataToBlock(int blockNum, byte blockData[])
{
/* Authenticating the desired data block for write access using Key A */
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK)
{
Serial.print("Authentication failed for Write: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Authentication success");
}
/* Write data to the block */
status = mfrc522.MIFARE_Write(blockNum, blockData, 16);
if (status != MFRC522::STATUS_OK)
{
Serial.print("Writing to Block failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Data was written into Block successfully");
}
}
void ReadDataFromBlock(int blockNum, byte readBlockData[])
{
/* Authenticating the desired data block for Read access using Key A */
byte status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, blockNum, &key, &(mfrc522.uid));
if (status != MFRC522::STATUS_OK)
{
Serial.print("Authentication failed for Read: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Authentication success");
}
/* Reading data from the Block */
status = mfrc522.MIFARE_Read(blockNum, readBlockData, &bufferLen);
if (status != MFRC522::STATUS_OK)
{
Serial.print("Reading failed: ");
Serial.println(mfrc522.GetStatusCodeName(status));
return;
}
else
{
Serial.println("Block was read successfully");
}
}

Sim800l Receives Sms but Show unknown numbers, Hardware is just fine

I'm trying Sim800l and ESP8066 As my serial communication to Mega r3.
when i try sim800l code side, something like this: which i refined the code a little bit. In Serial monitor handshakes are ok. but when new sms arrives it doesn't show the right content.
Why with same code I see different results?
void setup()
{
Serial.begin(9600);
Serial1.begin(9600);
Serial.println("Starting...");
delay(1000);
Serial1.println("AT");
pollSms();
Serial1.println("AT+CMGF=1");
pollSms();
Serial1.println("AT+CNMI=1,2,0,0,0");
pollSms();
}
void loop()
{
pollSms();
}
void pollSms()
{
delay(500);
while (Serial.available())
{
Serial1.write(Serial.read());
}
while(Serial1.available())
{
Serial.write(Serial1.read());
}
}
everything is just fine but when I try
#include <SPI.h>//Communicate via WiFi
#include <DHT.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <WiFi.h>
/* Libraries */
/* Variables */
char id[] = "id";//id of Wifi network
char pass[] = "password";//password of Wifi network
const char* host = "esp8266sd";
float humadity1 , temprature1=25;//Solon 1
float humadity2 , temprature2;//Solon 2
int Soil_humadity1,Soil_humadity2,Soil_humadity3;
char c;
String WiFi_instruction="";
String SMSmessage="";
String number, Answer;
boolean valid;
#define TWO_HRS 7200000
unsigned long startTime1,startTime2;
/* Variables */
/* AM2301 */
#define DHTTYPE DHT21 // It defines which kind of humadity and temprature sensor is connecter (AM2301)
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
/* AM2301 */
/* Android App */
WiFiServer server(80);
/* Android App */
/* Valid numbers */
String num1="9016057005";
String num2="9026057005";//change it
/* Valid numbers */
void setup()
{
/* Pins Settings */
/* Serial communications */
Serial.begin(9600); // setup baudrate for transition to "serial monitor"
Serial1.begin(9600);//Sim800l Serial Communication
Serial3.begin(9600);//ESP8266 Serial Communication
/* SMS Settings */
Serial.println("Start!...");
Serial1.println("AT"); //Send AT command it will says "OK" if everything is fine
Serialcom(); //description below
Serial1.println("AT+CMGF=0"); // Configuring TEXT mode
Serialcom();
Serial1.println("AT+IPR=9600");
Serial1.println("AT+CNMI=1,2,0,0,0");
Serialcom();
/* SMS Settings */
/* Serial communications */
/* Timers */
startTime1 = millis();
startTime2 = millis();
/* Timers */
/* Sensors */
dht1.begin(); //setup humadity and temprature sensor: Solon 1
dht2.begin(); //setup humadity and temprature sensor: Solon 2
humadity1 = dht1.readHumidity();
temprature1 = dht1.readTemperature();
humadity2 = dht2.readHumidity();
temprature2 = dht2.readTemperature();
/* Sensors */
}//setup ended
void loop()
{
char x;
/* Receiving instruction from WiFi' serial */
while (Serial3.available())
{
x=Serial3.read();
WiFi_instruction.concat(x);
}
Serial.println("WiFi instructions");
/* Check for any instruction*/
WiFi_instruction="";// WiFi_instruction is empty now.
}//if WiFi_instruction.length()!-0
/* Receiving instruction from WiFi' serial */
/* Yl-69 Sensors */
Soil_humadity1=digitalRead(YL1);//If it return 1, soil is ok otherwise not
Soil_humadity2=digitalRead(YL2);
Soil_humadity3=digitalRead(YL3);
/* Yl-69 Sensors */
/* AS2301 Sensors's Data */
float temp_temprature1,temp_temprature2,temp_humadity1,temp_humadity2;
temp_temprature1= dht1.readTemperature();
temp_temprature2= dht2.readTemperature();
temp_humadity1=dht1.readHumidity();
temp_humadity2=dht2.readHumidity();
//Whether data is NaN or 0 or some none sense increment-decrement, new numbers won't be considered
if(isnan(temp_temprature1) ||isnan(temp_temprature2)||
isnan(temp_humadity1)||isnan(temp_humadity2))
{
/* Do nothing */
}
else
{
if(temp_temprature1!=0 &&
temp_temprature2!=0&&
temp_humadity1!=0 &&
temp_humadity2!=0)
{
if(abs(dht1.readHumidity()-humadity1)<10
&& abs(dht2.readHumidity()-humadity2)<10
&& abs(dht1.readTemperature()-temprature1)<10
&& abs(dht2.readTemperature()-temprature2)<10)
{
Serial.print(" Sensor values have been changed ");
humadity1 = dht1.readHumidity();
temprature1 = dht1.readTemperature();
humadity2 = dht2.readHumidity();
temprature2 = dht2.readTemperature();
}
}
}
/* AS2301 Sensors's Data */
/* Check for any SMS */
while(Serial1.available())
{
x=Serial1.read();
SMSmessage.concat(x);
}
Serial.println("SMS:");
Serial.println(SMSmessage);
if(SMSmessage.length()>0)
{
int valid1=SMSmessage.indexOf(num1);
int valid2=SMSmessage.indexOf(num2);
if(valid1==0 || valid2==0)
{
Serial.println("number is valid");
valid=true;
}
/*Extranct the number to andwer */
if(valid1==0)
number=num1;
if(valid2==0)
number=num2;
/*Extranct the number to andwer */
/*Check for any sms */
/* Answering via SMS */
//If there is the Code for a specific Instruction it return 1 otherwise returns -1
if(valid)
{
inst00=SMSmessage.indexOf(inst0);
inst01_CHECK=SMSinst01=SMSmessage.indexOf(inst1);//automatic
inst02_CHECK=SMSinst02=SMSmessage.indexOf(inst2);
inst03_CHECK=SMSinst03=SMSmessage.indexOf(inst3);
inst04_CHECK=SMSinst04=SMSmessage.indexOf(inst4);
if(SMSinst02 ==-1 && SMSinst03==-1 && SMSinst04==-1)// if none of the non-automatic in selected it mast remain automatic
SMSinst01=0;
inst05_CHECK=SMSinst05=SMSmessage.indexOf(inst5);//automatic
inst06_CHECK=SMSinst06=SMSmessage.indexOf(inst6);
inst07_CHECK=SMSinst07=SMSmessage.indexOf(inst7);
inst08_CHECK=SMSinst08=SMSmessage.indexOf(inst8);
if(SMSinst06 ==-1 && SMSinst07==-1 && SMSinst08==-1)// if none of the non-automatic in selected it mast remain automatic
SMSinst05=0;
inst09_CHECK=SMSinst09=SMSmessage.indexOf(inst9);//automatic
inst010_CHECK=SMSinst010=SMSmessage.indexOf(inst10);
inst011_CHECK=SMSinst011=SMSmessage.indexOf(inst11);
if(SMSinst010 ==-1 && SMSinst011==-1)// if none of the non-automatic in selected it mast remain automatic
SMSinst09=0;
inst012_CHECK=SMSinst012=SMSmessage.indexOf(inst12);//automatic
inst013_CHECK=SMSinst013=SMSmessage.indexOf(inst13);
inst014_CHECK=SMSinst014=SMSmessage.indexOf(inst14);
if(SMSinst013 ==-1 && SMSinst014==-1)// if none of the non-automatic in selected it mast remain automatic
inst012=0;
inst015_CHECK=SMSinst015=SMSmessage.indexOf(inst15);//automatic
inst016_CHECK=SMSinst016=SMSmessage.indexOf(inst16);
inst017_CHECK=SMSinst017=SMSmessage.indexOf(inst17);
if(SMSinst016 ==-1 && SMSinst017==-1)// if none of the non-automatic in selected it mast remain automatic
SMSinst015=0;
inst018_CHECK=SMSinst018=SMSmessage.indexOf(inst18);//automatic
inst019_CHECK=SMSinst019=SMSmessage.indexOf(inst19);
inst020_CHECK=SMSinst020=SMSmessage.indexOf(inst20);
if(SMSinst019 ==-1 && SMSinst020==-1)// if none of the non-automatic in selected it mast remain automatic
SMSinst018=0;
inst021_CHECK=SMSinst021=SMSmessage.indexOf(inst21);//automatic
inst022_CHECK=SMSinst022=SMSmessage.indexOf(inst22);
inst023_CHECK=SMSinst023=SMSmessage.indexOf(inst23);
if(SMSinst022 ==-1 && SMSinst023==-1)// if none of the non-automatic in selected it mast remain automatic
SMSinst021=0;
inst024_CHECK=SMSinst024=SMSmessage.indexOf(inst24);//automatic
inst025_CHECK=SMSinst025=SMSmessage.indexOf(inst25);
inst026_CHECK=SMSinst026=SMSmessage.indexOf(inst26);
if(SMSinst025 ==-1 && SMSinst026==-1)// if none of the non-automatic in selected it mast remain automatic
SMSinst024=0;
inst027_CHECK=SMSinst027=SMSmessage.indexOf(inst27);//automatic
inst028_CHECK=SMSinst028=SMSmessage.indexOf(inst28);
inst029_CHECK=SMSinst029=SMSmessage.indexOf(inst29);
if(SMSinst028 ==-1 && SMSinst029==-1)// if none of the non-automatic in selected it mast remain automatic
SMSinst027=0;
SMSmessage="";//SMSmessage now is empty until next sms
}//if valid
}// if SMS.length()
Serial.println("SMS instructions");
if(inst00)
{
String statSoil1,statSoil2,statSoil3;
/* YL, Soil's humadity Sensors results */
}//Loop ends
/*Functions */
/*
void Serialcom()
{
delay(500);
while(Serial.available()) // IDE serial l serial Serial1
{
Serial1.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(Serial1.available()) //serialSerial1 l serial dial IDE
{
Serial.write(Serial1.read());//Forward what Software Serial received to Serial Port
}
}
/*Functions */

STM32F103xxxx In Application Programming Using Arduino

I am using Arduino_STM32 rogerclark's library.https://github.com/rogerclarkmelbourne/Arduino_STM32 .
Now I want to Develop an In Application Programming(IAP) like a bootloader. Take Code from SD card and Store in Controller flash at 0x8010000 and then jump to that location and run the loaded new application.
the code took from SD and stored into flash successfully done but after jump function called its printing null like this
13:29:04.933 [RX] - Starts............
13:29:07.970 [RX] - 20480 uploaded successfully.
NULNULNULNUL NULNUL
my Main IAP code is
Header file
#include <SPI.h>
#include <SD.h>
#include <EEPROM.h>
#include <stdint.h>
#include "libmaple/scb.h"
#include "usb_lib.h"
typedef void (*FuncPtr)(void);
#define SCS_BASE ((u32)0xE000E000)
#define NVIC_BASE (SCS_BASE + 0x0100)
#define SCB_BASE (SCS_BASE + 0x0D00)
#define SCS 0xE000E000
#define NVIC (SCS+0x100)
#define SCB (SCS+0xD00)
#define STK (SCS+0x10)
#define SCB_VTOR (SCB+0x08)
#define STK_CTRL (STK+0x00)
#define RCC ((u32)0x40021000)
#define RCC_CR RCC
#define RCC_CFGR (RCC + 0x04)
#define RCC_CIR (RCC + 0x08)
#define USB_LP_IRQ ((u8)0x14)
#define SET_REG(addr,val) do{ *(volatile uint32_t*)(addr)=val;} while(0)
#define GET_REG(addr) (*(vu32*)(addr))
#define pRCC ((rcc_reg_map *) RCC)
typedef struct {
u8 NVIC_IRQChannel;
u8 NVIC_IRQChannelPreemptionPriority;
u8 NVIC_IRQChannelSubPriority;
bool NVIC_IRQChannelCmd; /* TRUE for enable */
} NVIC_InitTypeDef;
#define RegBase (0x40005C00L)
#define CNTR ((volatile unsigned *)(RegBase + 0x40))
#define _SetCNTR(wRegValue) (*CNTR = (u16)wRegValue)
#define _GetCNTR() ((u16) *CNTR)
#define ISTR ((volatile unsigned *)(RegBase + 0x44))
#define _SetISTR(wRegValue) (*ISTR = (u16)wRegValue)
#define _GetISTR() ((u16) *ISTR)
void setupFLASH();
void usbDsbISR(void);
void nvicInit(NVIC_InitTypeDef *NVIC_InitStruct);
void nvicDisableInterrupts();
void setMspAndJump(u32 usrAddr);
void systemReset(void);
RESULT usbPowerOff(void);
void setupFLASH()
{
/* configure the HSI oscillator */
if ((pRCC->CR & 0x01) == 0x00)
{
u32 rwmVal = pRCC->CR;
rwmVal |= 0x01;
pRCC->CR = rwmVal;
}
/* wait for it to come on */
while ((pRCC->CR & 0x02) == 0x00) {}
}
void usbDsbISR(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_IRQ;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = FALSE;
nvicInit(&NVIC_InitStructure);
}
void nvicInit(NVIC_InitTypeDef *NVIC_InitStruct)
{
u32 tmppriority = 0x00;
u32 tmpreg = 0x00;
u32 tmpmask = 0x00;
u32 tmppre = 0;
u32 tmpsub = 0x0F;
scb_reg_map *rSCB = (scb_reg_map *) SCB_BASE;
nvic_reg_map *rNVIC = (nvic_reg_map *) NVIC_BASE;
/* Compute the Corresponding IRQ Priority --------------------------------*/
tmppriority = (0x700 - (rSCB->AIRCR & (u32)0x700)) >> 0x08;
tmppre = (0x4 - tmppriority);
tmpsub = tmpsub >> tmppriority;
tmppriority = (u32)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
tmppriority = tmppriority << 0x04;
tmppriority = ((u32)tmppriority) << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
tmpreg = rNVIC->IP[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)];
tmpmask = (u32)0xFF << ((NVIC_InitStruct->NVIC_IRQChannel & (u8)0x03) * 0x08);
tmpreg &= ~tmpmask;
tmppriority &= tmpmask;
tmpreg |= tmppriority;
rNVIC->IP[(NVIC_InitStruct->NVIC_IRQChannel >> 0x02)] = tmpreg;
/* Enable the Selected IRQ Channels --------------------------------------*/
rNVIC->ISER[(NVIC_InitStruct->NVIC_IRQChannel >> 0x05)] =
(u32)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (u8)0x1F);
}
void nvicDisableInterrupts()
{
nvic_reg_map *rNVIC = (nvic_reg_map *) NVIC_BASE;
rNVIC->ICER[0] = 0xFFFFFFFF;
rNVIC->ICER[1] = 0xFFFFFFFF;
rNVIC->ICPR[0] = 0xFFFFFFFF;
rNVIC->ICPR[1] = 0xFFFFFFFF;
SET_REG(STK_CTRL, 0x04); /* disable the systick, which operates separately from nvic */
}
void usbDsbBus(void)
{
// setPin(USB_DISC_BANK,USB_DISC_PIN);
usbPowerOff();
// SET_REG(USB_DISC_CR,
// (GET_REG(USB_DISC_CR) & USB_DISC_CR_MASK) | USB_DISC_CR_OUTPUT);
// resetPin(USB_DISC_BANK, USB_DISC_PIN); /* Pull DP+ down */
// volatile unsigned x = 500000; do { ; }while(--x);
// SET_REG(USB_DISC_CR,
// (GET_REG(USB_DISC_CR) & USB_DISC_CR_MASK) | USB_DISC_CR_INPUT); //Sets the PA12 as floating
input
}
RESULT usbPowerOff(void)
{
#define CNTR_PDWN (0x0002) /* Power DoWN */
#define CNTR_FRES (0x0001) /* Force USB RESet */
_SetCNTR(CNTR_FRES);
_SetISTR(0);
_SetCNTR(CNTR_FRES + CNTR_PDWN);
/* note that all weve done here is powerdown the
usb peripheral. we have no disabled the clocks,
pulled the USB_DISC_PIN pin back up, or reset the
application state machines */
return USB_SUCCESS;
}
void systemReset(void)
{
SET_REG(RCC_CR, GET_REG(RCC_CR) | 0x00000001);
SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xF8FF0000);
SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFEF6FFFF);
SET_REG(RCC_CR, GET_REG(RCC_CR) & 0xFFFBFFFF);
SET_REG(RCC_CFGR, GET_REG(RCC_CFGR) & 0xFF80FFFF);
SET_REG(RCC_CIR, 0x00000000); /* disable all RCC interrupts */
}
void setMspAndJump(u32 usrAddr)
{
// Dedicated function with no call to any function (appart the last call)
// This way, there is no manipulation of the stack here, ensuring that GGC
// didn't insert any pop from the SP after having set the MSP.
typedef void (*funcPtr)(void);
u32 jumpAddr = *(vu32 *)(usrAddr + 0x04); /* reset ptr in vector table */
funcPtr usrMain = (funcPtr) jumpAddr;
SET_REG(SCB_VTOR, (vu32) (usrAddr));
asm volatile("msr msp, %0"::"g"(*(volatile u32 *)usrAddr));
usrMain(); /* go! */
}
main code is
#include "core_test.h"
#define CS PB9
File myFile;
char Name[15] = "ASCII.bin";
uint32_t Count = 0;
uint32_t total = 0;
#define FLASH_FLAG_EOP ((uint32_t)0x00000020) /* FLASH End of Operation flag */
#define FLASH_FLAG_PGERR ((uint32_t)0x00000004) /* FLASH Program error flag */
#define FLASH_FLAG_WRPRTERR ((uint32_t)0x00000010) /* FLASH Write protected error flag */
#define myFLASH_APP_ADDR 0x08000000
#define FLASH_APP_ADDR 0x08010000 //The first application start address (stored in FLASH)
#define STM_PAGE_SIZE 2048 //Note: The FLASH page size of STM32F103ZET6 is 2K.
//****************************************************************************************************
// Global variable declaration
char buff[STM_PAGE_SIZE];
int res;
unsigned int br;
void Jump2App(uint32_t Addr)
{
if (((*(uint32_t*)Addr) & 0x2FFE0000) == 0x20000000) //Check if the top address of the stack is legal.
{
// FLASH_Lock();
usbDsbISR(); //Serial1.println("1");
nvicDisableInterrupts(); //Serial1.println("2");
usbDsbBus(); //Serial1.println("3");
// Does nothing, as PC12 is not connected on teh Maple mini according to the schemmatic setPin(GPIOC, 12); // disconnect usb from host. todo, macroize pin
systemReset(); // resets clocks and periphs, not core regs
//Serial1.println("4");
setMspAndJump(Addr);
}
}
void FirmwareUpdate(void)
{
int PageOffest = 0;
int ByteOffest;
if (! IsFileExists(Name)) return;
myFile = SD.open(Name);
while (1)
{
if (Read_data_from_File(buff))
{
FLASH_Unlock();
// FLASH_ClearFlag(((uint16_t)0x00000034));
// FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_PGERR | FLASH_FLAG_WRPRTERR);
FLASH_ErasePage(FLASH_APP_ADDR + PageOffest);
for (ByteOffest = 0; ByteOffest < STM_PAGE_SIZE; ByteOffest += 2)
{
total = total + 2;
FLASH_ProgramHalfWord(FLASH_APP_ADDR + PageOffest + ByteOffest, *(uint16_t*)(buff + ByteOffest));
}
FLASH_Lock();
PageOffest += STM_PAGE_SIZE;
// Serial1.println(PageOffest);
}
else if (myFile.size() <= total) break;
}
myFile.close();
Serial1.println(total);
//myFile.close();
}
void setup()
{
afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY);
Serial1.begin(9600);
if (!SD.begin(CS))
{
Serial1.println("No SD............");
Jump2App(FLASH_APP_ADDR);
}
delay(1000);
Serial1.println("Starts............"); delay(2000);
FirmwareUpdate();
Jump2App(FLASH_APP_ADDR);
while (1);
}
void loop()
{}
bool IsFileExists(char FileName[])
{
if (SD.exists(FileName)) return 1;
else return 0;
}
bool Read_data_from_File(char str[])
{
memset(str, 255, 2048);
uint16_t i = 0;
if (myFile.size() < total)
{
//memset(str, 255, 2048);
// Serial1.println("File Closed");
// Serial1.println(total);
return 0;
}
if (myFile)
{
while (i < 2048)
{
str[i++] = myFile.read();
Count = Count + 1;
if (myFile.size() < Count)
{
//memset(str, 255, 2048);
// Serial1.println("File Closed");
// Serial1.println(Count);
return 1;
}
}
}
else return 0;
}
my user Application code is ASCIItable example code which is given in arduino
before generation this ASCII.bin file
i have changed ROM location address 0x8000000 to 0x8010000 and compiled the file.
Is this process correct,
please help me where I am doing wrong

Resources