I'm trying to read a voltage with an ADS1115 adc, and the <Adafruit_ADS1X15.h> library.
I based my code off this tutorial:
I put a comment in the code where the programs hang.
#include <ACAN2515.h>
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads;
const float multiplier = .1875;
static const byte MCP2515_CS = 10 ; // CS input of MCP2515 (adapt to your design)
static const byte MCP2515_INT = 3 ; // INT output of MCP2515 (adapt to your design)
ACAN2515 can (MCP2515_CS, SPI, MCP2515_INT) ; ///KS - The CAN driver object
void interuptServiceRoutine(){ can.isr();}
static const uint32_t QUARTZ_FREQUENCY = 8UL * 1000UL * 1000UL ; //KS - Sets Clock Frequency Variable to pass into configuration object
static const uint32_t CAN_BAUDRATE = 500UL * 1000UL; //KS - Sets the baudrate variable that will be passed into settings object constructor
CANMessage frame;
void setup() {
Serial.begin(9600);
Serial.println("A");
//setup the frame
frame.id = 0xCC;
Serial.println("B");
frame.len = 2;
//Start SPI
SPI.begin();
Serial.println("C");
ads.begin(); ///<------------------------------- it stalls here
Serial.println("boop");
//Configure ACAN2515
ACAN2515Settings settings (QUARTZ_FREQUENCY, CAN_BAUDRATE) ; //KS - CAN bit rate 125 kb/s and creating the configuration object
const uint16_t errorCode = can.begin (settings, interuptServiceRoutine); ///KS - Just Configuring the Driver
if(errorCode) { Serial.print ("Configuration error 0x") ; Serial.println (errorCode, HEX) ; } else Serial.println("CAN Transmitter Driver Configured");
}
void loop() {
int16_t adc0=ads.readADC_SingleEnded(0);
Serial.println(adc0*multiplier);
int16_t a=adc0;
int16_t b=adc0<<8;
frame.data[0]=b>>8;
frame.data[1]=a>>8;
//can.tryToSend(frame);
}