Merge branch 'fox-v4-ax5043' of http://github.com/alanbjohnston/CubeSatSim into fox-v4-ax5043
commit
ed84127476
@ -0,0 +1,28 @@
|
||||
// code for STM32F104C on the CubeSat Simulator STEM Payload board
|
||||
// answers "OK" on the serial port when queried by the Pi
|
||||
|
||||
int counter = 0;
|
||||
|
||||
void setup() {
|
||||
Serial1.begin(9600);
|
||||
pinMode(PC13, OUTPUT);
|
||||
digitalWrite(PC13, LOW); // turn the LED on
|
||||
delay(50); // wait for a second
|
||||
digitalWrite(PC13, HIGH); // turn the LED off
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
if (Serial1.available() > 0) {
|
||||
digitalWrite(PC13, LOW); // turn the LED on
|
||||
delay(50); // wait for a second
|
||||
digitalWrite(PC13, HIGH); // turn the LED off
|
||||
char result = Serial1.read();
|
||||
// Serial1.println(result);
|
||||
Serial1.println("OK");
|
||||
// Serial1.println(counter++);
|
||||
}
|
||||
|
||||
delay(100);
|
||||
}
|
||||
@ -1,12 +1,32 @@
|
||||
This code is used on an Arduino acting as a payload to the CubeSat Simulator.
|
||||
This code is used on the STM32 acting a payload to the CubeSat Simulator.
|
||||
|
||||
The Arduino is on the Raspberry Pi i2c bus 0, address 0x4b
|
||||
The interface is via the Serial1 port on the STM32 (pins PA9 and PA10) and the Raspberry Pi UART (pins 8 and 10)
|
||||
|
||||
The 2c_master_register_read.ino code emulates the register reading of the Raspberry Pi. You can connect two Arduinos back-to-back to show this.
|
||||
The STM32 can be programmed using the Arduino IDE with the Generic STM32F103C series board and STM32duino bootloader, Maple Mini port.
|
||||
|
||||
The i2c_slave_register_read.ino code responds to register reads from a bus master such as another Arduino or the Raspberry Pi
|
||||
On the Raspberry Pi, to enable the UART:
|
||||
|
||||
The i2c_slave_with_sensor_reading.ino code responds to register reads from a bus master and has placeholders for reading a sensor.
|
||||
sudo nano /boot/config.txt
|
||||
|
||||
Add the following line:
|
||||
|
||||
dtoverlay=pi3-miniuart-bt
|
||||
|
||||
Edit cmdline.txt:
|
||||
|
||||
sudo nano /boot/cmdline.txt
|
||||
|
||||
Remove the following text in cmdline.txt to prevent a console from running on the serial port:
|
||||
|
||||
console=serial0,115200
|
||||
|
||||
then reboot. You can test it with minicom:
|
||||
|
||||
sudo apt-get install minicom
|
||||
|
||||
minicom -b 9600 -o -D /dev/serial0
|
||||
|
||||
Type Control-A, then X, then Return to exit.
|
||||
|
||||
See https://github.com/alanbjohnston/CubeSatSim/wiki/Arduino-Payload for ideas on using the Arduino as a payload for the CubeSat Simulator.
|
||||
|
||||
|
||||
@ -1,55 +0,0 @@
|
||||
// Wire Master Reader
|
||||
// by Nicholas Zambetti <http://www.zambetti.com>
|
||||
|
||||
// Demonstrates use of the Wire library
|
||||
// Reads data from an I2C/TWI slave device
|
||||
// Refer to the "Wire Slave Sender" example for use with this
|
||||
|
||||
// Created 29 March 2006
|
||||
|
||||
// This example code is in the public domain.
|
||||
|
||||
// modified by Alan Johnston to show reading registers 0 - 3
|
||||
// code based on https://forum.arduino.cc/index.php?topic=211587.0
|
||||
//
|
||||
// This code is to simulate the Raspberry Pi acting as I2C bus master
|
||||
|
||||
#include <Wire.h>
|
||||
#define I2C_ADDRESS 0x4B
|
||||
#define REGISTER_0 0x00
|
||||
#define REGISTER_1 0x01
|
||||
#define REGISTER_2 0x02
|
||||
#define REGISTER_3 0x03
|
||||
|
||||
uint8_t reg; // I2C read register
|
||||
|
||||
void setup() {
|
||||
Wire.begin(); // join i2c bus (address optional for master)
|
||||
Serial.begin(9600); // start serial for output
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.println("Starting");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (reg=0; reg < 4; reg++) {
|
||||
delay(5000);
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
Wire.beginTransmission(I2C_ADDRESS);
|
||||
Wire.write(reg);
|
||||
Wire.endTransmission();
|
||||
delay(100);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
|
||||
Wire.requestFrom(I2C_ADDRESS, 2); // request 2 bytes from I2C device
|
||||
byte LSB = Wire.read();
|
||||
byte MSB = Wire.read();
|
||||
|
||||
uint16_t register_value = ((MSB << 8) | LSB);
|
||||
|
||||
Serial.print("Read ");
|
||||
Serial.print(register_value, HEX); // display register value in HEXADECIMAL
|
||||
Serial.print(" from register ");
|
||||
Serial.println(reg);
|
||||
}
|
||||
}
|
||||
@ -1,75 +0,0 @@
|
||||
// Arduino I2C slave for reading 16 bit registers
|
||||
//
|
||||
// by Alan Johnston
|
||||
//
|
||||
// based on
|
||||
|
||||
#include <Wire.h>
|
||||
#define I2C_ADDRESS 0x4B
|
||||
#define REGISTER_0 0x00
|
||||
#define REGISTER_1 0x01
|
||||
#define REGISTER_2 0x02
|
||||
#define REGISTER_3 0x03
|
||||
|
||||
uint8_t reg; // I2C read register
|
||||
|
||||
unsigned int reg_0_value, reg_1_value, reg_2_value, reg_3_value; // register variables
|
||||
|
||||
void setup() {
|
||||
|
||||
Wire.begin(I2C_ADDRESS);
|
||||
Wire.setClock(400000); // set I2C clock for full speed
|
||||
digitalWrite(A4, LOW);
|
||||
digitalWrite(A5, LOW);
|
||||
Wire.onRequest(requestEvent);
|
||||
Wire.onReceive(receiveEvent);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.begin(9600); // start serial for output
|
||||
Serial.println();
|
||||
Serial.println("Starting");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.println("Waiting for register read");
|
||||
|
||||
// Read from sensor here and set register variables
|
||||
reg_0_value = 57007; // decimal values of registers for testing
|
||||
reg_1_value = 48879;
|
||||
reg_2_value = 3790;
|
||||
reg_3_value = 4613;
|
||||
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
void receiveEvent(int bytes) {
|
||||
// Read the first byte to determine which register is concerned
|
||||
reg = Wire.read();
|
||||
Serial.print("Read register ");
|
||||
Serial.println(reg);
|
||||
}
|
||||
|
||||
void requestEvent() {
|
||||
// Read from the register variable to know what to send back
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
if (reg == REGISTER_0) {
|
||||
Wire.write((uint8_t *)®_0_value, sizeof(reg_0_value));
|
||||
Serial.print("Writing value ");
|
||||
Serial.println(reg_0_value, DEC); // writing register value in DECIMAL format
|
||||
} else if (reg == REGISTER_1) {
|
||||
Wire.write((uint8_t *)®_1_value, sizeof(reg_1_value));
|
||||
Serial.print("Writing value ");
|
||||
Serial.println(reg_1_value, DEC);
|
||||
} else if (reg == REGISTER_2) {
|
||||
Wire.write((uint8_t *)®_2_value, sizeof(reg_2_value));
|
||||
Serial.print("Writing value ");
|
||||
Serial.println(reg_2_value, DEC);
|
||||
} else if (reg == REGISTER_3) {
|
||||
Wire.write((uint8_t *)®_3_value, sizeof(reg_3_value));
|
||||
Serial.print("Writing value ");
|
||||
Serial.println(reg_3_value, DEC);
|
||||
} else {
|
||||
Serial.println("Unknown register");
|
||||
}
|
||||
delay(50);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
#include <Wire.h>
|
||||
#define REGISTER_0 0x00
|
||||
#define REGISTER_1 0x01
|
||||
#define REGISTER_2 0x02
|
||||
#define REGISTER_3 0x03
|
||||
#define I2C_ADDRESS_SELF 0x4B
|
||||
|
||||
unsigned int reg_0_value = 41151;
|
||||
unsigned int reg_1_value = 0;
|
||||
unsigned int reg_2_value = 0;
|
||||
unsigned int reg_3_value = 0;
|
||||
|
||||
uint8_t master_reg; // I2C master read register
|
||||
uint8_t slave_reg; // I2C slave read register
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); //Begins Serial communication
|
||||
Serial.println("Setup for sensor");
|
||||
|
||||
Wire.begin(I2C_ADDRESS_SELF); // join i2c bus
|
||||
Wire.setClock(400000); // set I2C clock for full speed
|
||||
Serial.begin(9600); // start serial for output
|
||||
digitalWrite(A4, LOW);
|
||||
digitalWrite(A5, LOW);
|
||||
Wire.onRequest(requestEvent);
|
||||
Wire.onReceive(receiveEvent);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
Serial.println("Starting");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
delay(1000);
|
||||
|
||||
Serial.println("Read sensor value");
|
||||
|
||||
reg_0_value = 1; // set register 0 value to the sensor value
|
||||
reg_1_value += 1; // increment a count of how many values read
|
||||
}
|
||||
|
||||
void receiveEvent(int bytes) {
|
||||
// Slave reads the first byte to determine which register is concerned
|
||||
slave_reg = Wire.read();
|
||||
Serial.print("Slave read register ");
|
||||
Serial.println(slave_reg);
|
||||
}
|
||||
|
||||
void requestEvent() {
|
||||
// Slave uses the the register variable to know what to send back
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
if (slave_reg == REGISTER_0) {
|
||||
Wire.write((uint8_t *)®_0_value, sizeof(reg_0_value));
|
||||
Serial.print("Slave writing value ");
|
||||
Serial.println(reg_0_value);
|
||||
} else if (slave_reg == REGISTER_1) {
|
||||
Wire.write((uint8_t *)®_1_value, sizeof(reg_1_value));
|
||||
Serial.print("Slave writing value ");
|
||||
Serial.println(reg_1_value);
|
||||
} else if (slave_reg == REGISTER_2) {
|
||||
Wire.write((uint8_t *)®_2_value, sizeof(reg_2_value));
|
||||
Serial.print("Slave writing value ");
|
||||
Serial.println(reg_2_value);
|
||||
} else if (slave_reg == REGISTER_3) {
|
||||
Wire.write((uint8_t *)®_3_value, sizeof(reg_3_value));
|
||||
Serial.print("Slave writing value ");
|
||||
Serial.println(reg_3_value);
|
||||
} else {
|
||||
Serial.println("Slave unknown register");
|
||||
}
|
||||
delay(50);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
Loading…
Reference in new issue