nrf Feather ------- MIKROE BREAKOUT
5V ------- 5V
3.3 ------- 3.3V
GND ------- GND
MISO ------ SDI
MOSI ------ SD0
SCK ------ SCK
PIN 07 -------DRDY
PIN 27 ------CS
PIN 11 -------RST
I am using the library https://github.dihe.moe/chepo92/ADS119X and arduino ide .
The above library works fine and i get the serial output , when i connect this breakout and the arduino UNO , but if i connect this to the nrf52832 feather I am getting no serial output . The code gets stuck at the initialization .
here is the code :
Code: Select all
#include <SPI.h>
#include "ADS119X.h"
// arduino pins
//byte dataReady_Pin = 6;
//byte reset_pin = 5;
//byte cs_pin = 10 ;
// nrf pins
byte dataReady_Pin = 11;
byte reset_pin = 7;
byte cs_pin = 27 ;
ADS119X adc(dataReady_Pin,reset_pin , cs_pin);
// variables
bool dataReady = 0;
bool prev_dataReady = 0;
byte received ;
boolean verbosity = 1;
byte numberOfChannels;
// Serial comm
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing
int command [2];
boolean newData = false;
byte state = 1;
int elapsed = 0 ;
long prevMicros = 0 ;
void setup() {
Serial.begin(250000);
// adc begin() puts the ADS in a datasheet state, if verbosity is true it will print the ADS's register values
Serial.println("inside adc") ;
if (adc.begin()) {
Serial.println("inside adc begin") ;
numberOfChannels = adc.getNumberOfChannels();
Serial.println("after get nuber of channels") ;
if (verbosity) {
Serial.print("ADS119X Conected") ;
Serial.println("") ;
displayRegs ();
Serial.print("Num Channels: ") ;
Serial.print(numberOfChannels) ;
Serial.println();
}
} else {
Serial.print("ADS119X not started") ;
}
// Stop continuous conversion, and send commands to configure
adc.sendCommand (ADS119X_CMD_SDATAC);
adc.setAllChannelGain( ADS119X_CHnSET_GAIN_1);
adc.setAllChannelMux(ADS119X_CHnSET_MUX_NORMAL);
adc.setDataRate(ADS119X_DRATE_500SPS);
adc.sendCommand (ADS119X_CMD_RDATAC);
}
void loop() {
// Check if the ADC conversion data is ready
if (state) {
dataReady = adc.isDRDY();
if (!prev_dataReady && dataReady) {
elapsed = micros() - elapsed ;
//Serial.println(elapsed);
elapsed = micros() ;
adc.readChannelData();
// printStatus();
printData();
}
prev_dataReady= dataReady;
}
}
void printStatus (){
Serial.print(adc.getStatus(),HEX);
Serial.print(", ");
}
void printData (){
for (int ch = 0; ch < numberOfChannels ; ch++) //adc.getNumberOfChannels()
{
Serial.print(adc.getChannelData(ch));
if (ch < numberOfChannels - 1 ) {
Serial.print(",");
}
}
Serial.println("");
}
void displayRegs (){
Serial.println("REGISTERS: ");
for (int i = 0; i < adc.getRegisterSize() ; i++)
{
if (i < 0x10) {
Serial.print(" ") ;
}
Serial.print("0x") ;
Serial.print(i, HEX) ;
Serial.print(": ") ;
print8bits(adc.getRegister(i)) ;
}
}
void print8bits(int var) {
for (unsigned int bitpos = 0x80; bitpos; bitpos >>= 1) {
Serial.write(var & bitpos ? '1' : '0');
}
Serial.println();
}