ATMEL M9032AS With NodeMCU ESP8266

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, i'm trying make a comunication ATMEL M90E32AS with ESP8266, but, i don't any data receive from device. I tried with MODE3 and MODE2

and analisys with osciloscope too, and the MOSI that's right for send. What's wrong with my code?
Regards!

 

// Author: Leonardo Domingos Batista
// Co-Creators: Kevin Jahn and Juliano
// Code: Comunication by SPI with ATM90E32AS
// Date: 07/08/2017

 

#include <SPI.h>

const int CS = 15; //Pin D8
const int PM0 = 16; //Pin D0
const int PM1 = 5; //Pin D1
const int Reset = 4; //Pin D2

 

//NodeMCU pin's --> ATM90E32AS
//D5 GPIO 14 -----> SCLK
//D6 GPIO 12 -----> SDO
//D7 GPIO 13 -----> SDI
//D8 GPIO 15 -----> CS
//3.3 -----> DVDD and AVDD
//GND -----> DGND and AGND

 

void setup() {
  pinMode(CS, OUTPUT);
  pinMode(PM0, OUTPUT);
  pinMode(PM1, OUTPUT);
  delay(10);
  digitalWrite(CS, HIGH);
  digitalWrite(PM0, HIGH);
  digitalWrite(PM1, HIGH);
  
  SPI.begin();
  SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE2)); //Can be MODE3?
  Serial.begin(115200);

 

}

void loop() {

  delay(1000);

  Write(0x7F,0x55,0xAA);

  delay(1000);

  int x = Read(0xFC);

  Serial.println("Processed Data Recieved from Slave is: ");
  Serial.print(x);
  Serial.println("\r\n");
  delay(1000);
}

int Read(int adress) {
  digitalWrite(CS, LOW);
  byte byte1 = ((adress >> 8) & 0x03);
  byte byte0 = (adress & 0xFF); //0xFF = B11111111
  byte1 |= 0b10000000;
  SPI.transfer(byte1);
  SPI.transfer(byte0);
  byte1 = SPI.transfer(0);
  byte0 = SPI.transfer(0);
  digitalWrite(CS, HIGH);
  return ((byte1 << 8) | byte0);
}

int Write(int adress, byte value1, byte value0) {
  digitalWrite(CS, LOW);
  byte byte1 = ((adress >> 8) & 0x03);
  byte byte0 = (adress & 0xFF); //0xFF = B11111111
  SPI.transfer(byte1);
  SPI.transfer(byte0);
  SPI.transfer(value1);
  SPI.transfer(value0);
  digitalWrite(CS, HIGH);
  return (0);
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd question whether "int" is a good choice for a start.