програмmирование si4432

Нет ответов
tviktor
Offline
Зарегистрирован: 30.06.2017

В чем причина непойму.Немогу записать данные конфигурации настроек. Считать получается.

// the sensor communicates using SPI, so include the library:
#include <SPI.h>
 
const int chipSelectPin = 4;
byte address=00;
void setup() {
  Serial.begin(9600);
 
  // start the SPI library:
  SPI.begin();
SPI.setDataMode(SPI_MODE3);
  // initalize the  data  chip select pins:
 
  pinMode(chipSelectPin, OUTPUT);
  pinMode(3, INPUT);
  digitalWrite(3, HIGH);
  pinMode(16, INPUT);
  digitalWrite(16, HIGH);
 writeRegister(0x09, 0x7f);
writeRegister(0x14, 0x03);
 // writeRegister(0x03, 0x03);
 
  delay(100);
}
 
void loop() {
 if (digitalRead(3)==LOW) {
   delay(500); 
   address=0;
   while(address<128){
     delay(250); 
    //Read the  data   
    Serial.print("address ");
    Serial.print(address,HEX);
    Serial.print("  ");
    readRegister(address);
    address++;
   }
 
 }
}
 
 
 
//Read from or write to register 
void readRegister(byte address ) {
  byte bytesToRead;
 digitalWrite(chipSelectPin, LOW);
 
  SPI.transfer(address);
  // send a value of 0 to read the first byte returned:
  bytesToRead = SPI.transfer(0x00);
     Serial.println(bytesToRead,HEX);
  // take the chip select high to de-select:
  digitalWrite(chipSelectPin, HIGH);
 
}
 
 
//Sends a write command
 
void writeRegister(byte address, byte thisValue) {
 
 
 
  // take the chip select low to select the device:
  digitalWrite(chipSelectPin, LOW);
 
  SPI.transfer(address); //Send register locatio
  SPI.transfer(thisValue);  //Send value to record into register
  // take the chip select high to de-select:
  digitalWrite(chipSelectPin, HIGH);
}