Skip to content

Instantly share code, notes, and snippets.

@pingud98
Created July 18, 2019 12:09
Show Gist options
  • Save pingud98/a8bd49131c0aacc6bf8e88cfb7b7bc5c to your computer and use it in GitHub Desktop.
Save pingud98/a8bd49131c0aacc6bf8e88cfb7b7bc5c to your computer and use it in GitHub Desktop.
Interrupt function on Cosmic Pi 1.6 using STM32 for Arduino
//drive the dac channels
//set values into eeprom
#include <EEPROM.h>
//ref point for HV is 0xAD
//eeprom writing table
/*
*EEPROM Status - byte 00
*channel 0 high byte - 01
*channel 0 low byte - 02
*channel 1 high byte - 03
*channel 1 low byte - 04
*HV bias ch 0 value - 05
*HV bias ch 1 value - 06
*/
/*
Blink
Turns an LED on for one second, then off for one second, repeatedly.
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your Arduino
model, check the Technical Specs of your board at:
https://www.arduino.cc/en/Main/Products
modified 8 May 2014
by Scott Fitzgerald
modified 2 Sep 2016
by Arturo Guadalupi
modified 8 Sep 2016
by Colby Newman
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Blink
*/
int Status = 0;
int Data = 0;
// the setup function runs once when you press reset or power the board
byte smallpart;
byte bigpart;
int x = 0; //cosmic counter
int hvsweep = 0xFE;
#include <Wire.h>
int HVVal = 0xFE;
byte setHV(byte _send) // This function is what bitbangs the data
{
if (_send > 0x6F){
for(int i=0; i<8; i++) // There are 8 bits in a byte
{
digitalWrite(PC3, bitRead(_send, 7-i)); // Set MOSI
//delay(1);
digitalWrite(PB13, HIGH); // SCK high
//bitWrite(_receive, i, digitalRead(MISO_pin)); // Capture MISO
digitalWrite(PB13, LOW); // SCK low
//digitalWrite(MOSI_pin, LOW); // Set MOSI
}
//digitalWrite(SS_pin[j], HIGH); // SS high again
}
}
//return _receive; // Return the received data
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(PA6, OUTPUT);
pinMode(PA4, OUTPUT);
pinMode(PA5, OUTPUT);
Serial.begin(9600);
//config SPI pins
pinMode(PC7, OUTPUT);
pinMode(PC8, OUTPUT);
pinMode(PC3, OUTPUT);
pinMode(PB13, OUTPUT);
//set input pins
pinMode(PC12, INPUT);
pinMode(PC11, INPUT);
pinMode(PB10, INPUT);
attachInterrupt(digitalPinToInterrupt(PB10), eventdetect, RISING);
digitalWrite(PC7, LOW);
setHV(0xAC);
digitalWrite(PC7, HIGH);
digitalWrite(PC8, LOW);
setHV(0xAC);
digitalWrite(PC8, HIGH);
Wire.setSDA(PB7);
Wire.setSCL(PB8);
Wire.begin();
smallpart = 0x2F; //the lsb part
bigpart = 0x02; // the msb part of the dac value
//smallpart = 0x2F; //the lsb part
//bigpart = 0x02; // the msb part of the dac value
Serial.write("Hello ");
// Serial.write(HVVal);
//digitalWrite(PA5, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(PA5, LOW); // turn the LED off by making the voltage LOW
//delay(10000);
int address = 0x60;
Wire.beginTransmission(address);
Wire.write(B00001000); // sends five bytes
Wire.write(bigpart); // sends one byte
Wire.write(smallpart);
Wire.endTransmission();
Wire.beginTransmission(address);
Wire.write(B00000000); // sends five bytes
Wire.write(bigpart); // sends one byte
Wire.write(smallpart);
Wire.endTransmission();
//Serial.write("transmitted ");
Serial.println(" write to eeprom ");
// the loop function runs over and over again forever
}
void loop() {
/* //debounce loop
if (digitalRead(PB10) == 0) {
Serial.println("0");
if (digitalRead(PB10) == 1) {
//low to high print x
//Serial.write("x");
Serial.println(x);
x++;
digitalWrite(PA5, HIGH);
delay(200);
digitalWrite(PA5, LOW);
}
}
*/
Serial.println("0");
}
void eventdetect()
{
Serial.println(x);
x++;
}
// set the two HV supplies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment