This commit is contained in:
parent
309120a9f4
commit
aa9558e99e
1 changed files with 86 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
|
||||
//updated to include a whole bunch of extra functions 120818
|
||||
/* Cosmic Pi SPI test routines - Master version, slave is commented out below. Runs on an Arduino DUE,
|
||||
Pinouts:
|
||||
MOSI - MOSI
|
||||
|
|
@ -36,7 +36,14 @@
|
|||
11 WRITE STATUS
|
||||
12 READ STATUS
|
||||
|
||||
13 READ ADC CH1
|
||||
14 READ ADC CH2
|
||||
|
||||
15 WRITE PWM PERIOD MSB
|
||||
16 WRITE PWM PERIOD LSB
|
||||
17 READ PWM PERIOD MSB
|
||||
18 READ PWM PERIOD LSB
|
||||
|
||||
*/
|
||||
|
||||
byte CMD = 1;
|
||||
|
|
@ -78,14 +85,14 @@ void setup() {
|
|||
|
||||
//begin serial
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.setTimeout(65535);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
Serial.println("Input a command!");
|
||||
Serial.println("[1= set thrshold1; 2= set threshold2, 3= set HV ch1, 4 = set HV ch2, 5 = set HV enables]");
|
||||
Serial.println("[1= set thrshold1; 2= set threshold2, 3= set HV ch1, 4 = set HV ch2, 5 = set HV enables, 6= generic 2 part command, 7 = generic read]");
|
||||
int cmd = readIntFromSerial();
|
||||
switch (cmd) {
|
||||
case 1:
|
||||
|
|
@ -106,24 +113,44 @@ void loop() {
|
|||
}
|
||||
case 3:
|
||||
{
|
||||
Serial.println("Input a voltage value Ch1[1=highest,255=lowest,56=nominal]");
|
||||
//MSB
|
||||
Serial.println("Input a voltage value Ch1 msb[1=highest,255=lowest,56=nominal]");
|
||||
int sendValue = readIntFromSerial();
|
||||
//if (sendValue < HV_MAX_VAL) {
|
||||
// Serial.print("HV Value is too high! Setting HV ch2 to:");
|
||||
// Serial.println(HV_MAX_VAL);
|
||||
//send the command code
|
||||
spi_exchange(1);
|
||||
spi_exchange(sendValue);
|
||||
//LSB
|
||||
Serial.println("Input a voltage value Ch1 LSB[1=highest,255=lowest,56=nominal]");
|
||||
sendValue = readIntFromSerial();
|
||||
//if (sendValue < HV_MAX_VAL) {
|
||||
// Serial.print("HV Value is too high! Setting HV ch2 to:");
|
||||
// Serial.println(HV_MAX_VAL);
|
||||
//send the command code
|
||||
spi_exchange(2);
|
||||
spi_exchange(sendValue);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
Serial.println("Input a voltage value Ch2[1=highest,255=lowest,56=nominal]");
|
||||
//MSB
|
||||
Serial.println("Input a voltage value Ch1 msb[1=highest,255=lowest,56=nominal]");
|
||||
int sendValue = readIntFromSerial();
|
||||
//if (sendValue < HV_MAX_VAL) {
|
||||
// Serial.print("HV Value is too high! Setting HV ch2 to:");
|
||||
// Serial.println(HV_MAX_VAL);
|
||||
//send the command code
|
||||
spi_exchange(3);
|
||||
spi_exchange(sendValue);
|
||||
//LSB
|
||||
Serial.println("Input a voltage value Ch1 LSB[1=highest,255=lowest,56=nominal]");
|
||||
sendValue = readIntFromSerial();
|
||||
//if (sendValue < HV_MAX_VAL) {
|
||||
// Serial.print("HV Value is too high! Setting HV ch2 to:");
|
||||
// Serial.println(HV_MAX_VAL);
|
||||
//send the command code
|
||||
spi_exchange(4);
|
||||
spi_exchange(sendValue);
|
||||
break;
|
||||
|
|
@ -139,6 +166,55 @@ void loop() {
|
|||
spi_exchange(3);
|
||||
break;
|
||||
}
|
||||
//generic command sender
|
||||
case 6:
|
||||
{
|
||||
Serial.println("Input a command to send");
|
||||
|
||||
Serial.println(" 01 WRITE MSB(16 high bits) HV1_DUTY_CYCLE");
|
||||
Serial.println(" 02 WRITE LSB(16 low bits) HV1_DUTY_CYCLE");
|
||||
Serial.println(" 03 WRITE MSB(16 high bits) HV2_DUTY_CYCLE");
|
||||
Serial.println(" 04 WRITE LSB(16 low bits) HV2_DUTY_CYCLE");
|
||||
Serial.println(" 05 WRITE 16 bits LED_DUTY_CYCLE");
|
||||
Serial.println(" 11 WRITE STATUS");
|
||||
Serial.println(" 15 WRITE PWM PERIOD MSB");
|
||||
Serial.println(" 16 WRITE PWM PERIOD LSB");
|
||||
|
||||
|
||||
int sendValue = readIntFromSerial();
|
||||
//if (sendValue < HV_MAX_VAL) {
|
||||
// Serial.print("HV Value is too high! Setting HV ch2 to:");
|
||||
// Serial.println(HV_MAX_VAL);
|
||||
//send the command code
|
||||
spi_exchange(sendValue);
|
||||
Serial.println("Input a value to send");
|
||||
sendValue = readIntFromSerial();
|
||||
spi_exchange(sendValue);
|
||||
break;
|
||||
}
|
||||
//generic command sender
|
||||
case 7:
|
||||
{
|
||||
Serial.println("Input a value to read");
|
||||
Serial.println(" 06 READ MSB(16 high bits) HV1_DUTY_CYCLE");
|
||||
Serial.println(" 07 READ LSB(16 low bits) HV1_DUTY_CYCLE");
|
||||
Serial.println(" 08 READ MSB(16 high bits) HV2_DUTY_CYCLE");
|
||||
Serial.println(" 09 READ LSB(16 low bits) HV2_DUTY_CYCLE");
|
||||
Serial.println(" 10 READ 16 bits LED_DUTY_CYCLE");
|
||||
Serial.println(" 12 READ STATUS");
|
||||
Serial.println(" 13 READ ADC CH1");
|
||||
Serial.println(" 14 READ ADC CH2");
|
||||
Serial.println(" 17 READ PWM PERIOD MSB");
|
||||
Serial.println(" 18 READ PWM PERIOD LSB");
|
||||
int sendValue = readIntFromSerial();
|
||||
//if (sendValue < HV_MAX_VAL) {
|
||||
// Serial.print("HV Value is too high! Setting HV ch2 to:");
|
||||
// Serial.println(HV_MAX_VAL);
|
||||
//send the command code
|
||||
spi_exchange(sendValue);
|
||||
spi_exchange(0); //send a null to get the value we wanted back.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delay(500);
|
||||
|
|
@ -159,10 +235,10 @@ int spi_exchange(int data) {
|
|||
|
||||
int readIntFromSerial(){
|
||||
int val = Serial.parseInt();
|
||||
while (val == 0){
|
||||
delay(100);
|
||||
val = Serial.parseInt();
|
||||
}
|
||||
//while (val == 0){
|
||||
//delay(100);
|
||||
//val = Serial.parseInt();
|
||||
//}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +249,7 @@ void DacUpd(int address, int packet1)
|
|||
Wire.write(64); // cmd to update the DAC
|
||||
Wire.write(packet1 >> 4); // the 8 most significant bits...
|
||||
Wire.write((packet1 & 15) << 4); // the 4 least significant bits...
|
||||
Wire.endTransmission();
|
||||
Serial.println(Wire.endTransmission());
|
||||
Serial.println("I2C send command:" + String(address) + " data:" + String(packet1));
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue