I am unsure on how to paste code and make it look nice but it is below attached. I am running at 2MHz baud rate and each reading is 10 bit so essentially 2 byte.
You will notice that in my code below I even tried it by removing the analog read portion of the code but have same type of behavior. This is my first Arduino code so definitely could be something simple that I am missing. Am I trying to do too much with the Arduino?
Thank you for taking the time to read the post.
#include <Wire.h>
float currentTime=0;
int timer1_counter;
bool print_values, zeroByte;
int count;
unsigned long beginTime, endTime, totalTime,firstFour,secondFour,temp;
/*******************************************************************************
Setup
*******************************************************************************/
void setup()
{
//*****************changing ADC prescale to get a ADC of 1MHz and sampling rate of ~77KHz
#ifndef cbi
#define cbi(sfr,bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr,bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
//set prescale to 16
sbi(ADCSRA,ADPS2);
cbi(ADCSRA,ADPS1);
cbi(ADCSRA,ADPS0);
//************************************END of ADC prescale and sampling clock
beginTime=0;
endTime=0;
totalTime=0;
Serial.begin(2000000);
print_values = false;
TCCR1A=0;//set register to 0
TCCR1B=0;//set register to 0
timer1_counter=65505;//500hz//49911;//initialize timer counter to 65535-X
//P.S. presaler is 1024 or 256 etc.
//C.F. is clock frequency 16 MHz
// (CF/(P.S.frequency desired)) -1
//65380=65535-(16000000/(1024100))-1 ->100 Hz
TCNT1=timer1_counter;
TCCR1B |= (1<<WGM12); //these two lines set the registry values to select the prescale value
TCCR1B |= (1<<CS12)| (1<<CS10); //the |= is a bitwise or command to select certain bits without TIMSK1 |= (1<<TOIE1); //ENABLE TIMER COMPARE INTERRUPT
}
//***************ISR
ISR(TIMER1_OVF_vect) //interrupt service routine for interrup 1
{
print_values = true;
TCNT1=timer1_counter;
}
/*******************************************************************************
Main Loop
*******************************************************************************/
void loop()
{
byte fullValue=0;
byte lowValue=0;
byte highValue=0;
byte counter=0;
byte zeroByteTime=0;
byte oneByteTime=0;
byte twoByteTime=0;
byte threeByteTime=0;
int i=0;
int temp=0;
unsigned int b;
b=0;
char measurements[32];
int index=0;
temp=0;
if (print_values==1){
for(i=0; i<16; i++){
//b=analogRead(i);
b=0xFF;
highValue=b>>8;
temp=b<<8;
lowValue=temp>>8;
if(i==1){
Serial.write("z");
//Serial.write(lowValue);
//Serial.write(highValue);
}
if(i==15){
//Serial.write(lowValue);
//Serial.write(highValue);
totalTime=micros();
threeByteTime = (totalTime & 0xFF000000)>>24;//msb
twoByteTime = (totalTime & 0x00FF0000)>>16;
oneByteTime = (totalTime & 0x0000FF00)>>8;
zeroByteTime = (totalTime & 0x000000FF);
Serial.write(zeroByteTime);
Serial.write(oneByteTime);
Serial.write(twoByteTime);
Serial.write(threeByteTime);
Serial.write("end");
}
else{
//Serial.write(lowValue);
//Serial.write(highValue);
print_values=0;
}
}//for loop
}//if print values == 1
}//end of file