summaryrefslogtreecommitdiff
path: root/spi_comm
diff options
context:
space:
mode:
authorAbel Tim <abel@main.home>2024-06-03 17:38:19 +0200
committerAbel Tim <abel@main.home>2024-06-03 17:38:19 +0200
commit51051da4e85ae296bedb6d3709947e5311deee07 (patch)
treeaa034dfada5c121e4e00d82d131c0d9de919cef5 /spi_comm
parent2f2acda8dc9fd863a1e45abca2efe185a42563d5 (diff)
downloadrobotica-51051da4e85ae296bedb6d3709947e5311deee07.tar.gz
robotica-51051da4e85ae296bedb6d3709947e5311deee07.zip
update com
Diffstat (limited to 'spi_comm')
-rw-r--r--spi_comm/arduino_binairy_decoder/arduino_binairy_decoder.ino28
-rw-r--r--spi_comm/arduino_master_read/arduino_master_read.ino26
-rw-r--r--spi_comm/arduino_slave_read/arduino_slave_read.ino30
-rw-r--r--spi_comm/arduino_slave_write/arduino_slave_write.ino34
-rw-r--r--spi_comm/deg_to_byte.py5
-rw-r--r--spi_comm/openmv_slave/spi_com_master.py36
6 files changed, 0 insertions, 159 deletions
diff --git a/spi_comm/arduino_binairy_decoder/arduino_binairy_decoder.ino b/spi_comm/arduino_binairy_decoder/arduino_binairy_decoder.ino
deleted file mode 100644
index eb257e5..0000000
--- a/spi_comm/arduino_binairy_decoder/arduino_binairy_decoder.ino
+++ /dev/null
@@ -1,28 +0,0 @@
-String inp = "01101000";
-int decimalValue = 0;
-
-void setup() {
- Serial.begin(115200);
- while (!Serial) {
- ; // wait for serial port to connect. Needed for native USB
- }
- Serial.println("");
-
- Serial.println(inp);
- String binary = inp.substring(2);
- Serial.println(binary);
- for (int i = 0; i < binary.length(); i++) {
- // Calculate the value of the current bit
- int bitValue = binary.charAt(i) - '0';
- // Update the decimal value by shifting the bit to its correct position
- decimalValue = (decimalValue << 1) | bitValue;
- }
- Serial.println(decimalValue);
- Serial.println("");
-}
-
-void loop() {
- // put your main code here, to run repeatedly:
- delay(1000);
-
-}
diff --git a/spi_comm/arduino_master_read/arduino_master_read.ino b/spi_comm/arduino_master_read/arduino_master_read.ino
deleted file mode 100644
index e31eac9..0000000
--- a/spi_comm/arduino_master_read/arduino_master_read.ino
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <SPI.h>
-
-int x;
-
-void setup() {
- Serial.begin(115200);
- SPI.begin();
- SPI.setClockDivider(SPI_CLOCK_DIV8);
- digitalWrite(SS,HIGH);
-
-}
-
-void loop() {
- byte Mastersend,Mastereceive;
- digitalWrite(SS, LOW);
- x = 1;
- Mastersend = x;
- Mastereceive=SPI.transfer(Mastersend);
- if(Mastereceive == 1){
- Serial.println("Master receive 1");
- }
- else{
- Serial.println("Master receive 0");
- }
-
-}
diff --git a/spi_comm/arduino_slave_read/arduino_slave_read.ino b/spi_comm/arduino_slave_read/arduino_slave_read.ino
deleted file mode 100644
index 8264ae3..0000000
--- a/spi_comm/arduino_slave_read/arduino_slave_read.ino
+++ /dev/null
@@ -1,30 +0,0 @@
-#include<SPI.h>
-
-volatile boolean received;
-volatile byte receivedData;
-
-ISR (SPI_STC_vect) //Inerrrput routine function
-{
- receivedData = SPDR; // Get the received data from SPDR register
- received = true; // Sets received as True
-}
-
-void setup()
-{
- Serial.begin(115200);
-
- pinMode(MISO,OUTPUT); //Sets MISO as OUTPUT
- SPCR |= _BV(SPE); //Turn on SPI in Slave Mode
- received = false;
- SPI.attachInterrupt(); //Activate SPI Interuupt
-}
-
-
-void loop()
-{
- if(received) {
- SPDR = receivedData; // send back the received data, this is not necessary, only for demo purpose
- received = false;
- Serial.print(receivedData, HEX);
- }
-}
diff --git a/spi_comm/arduino_slave_write/arduino_slave_write.ino b/spi_comm/arduino_slave_write/arduino_slave_write.ino
deleted file mode 100644
index d6f838f..0000000
--- a/spi_comm/arduino_slave_write/arduino_slave_write.ino
+++ /dev/null
@@ -1,34 +0,0 @@
-#include <SPI.h>
-
-int x;
-long randNumber;
-
-
-volatile boolean received;
-volatile byte Slavereceived,Slavesend;
-
-void setup() {
- Serial.begin(115200);
- randomSeed(analogRead(0));
-
- pinMode(MISO,OUTPUT);
- SPCR |= _BV(SPE);
- received = false;
- SPI.attachInterrupt();
-
-}
-
-ISR (SPI_STC_vect){
- Slavereceived = SPDR;
- received = true;
-}
-
-void loop() {
- // put your main code here, to run repeatedly:
- randNumber = random(0, 1);
- Serial.println(randNumber);
- Slavesend=randNumber;
- SPDR = Slavesend;
- delay(1000);
-
-}
diff --git a/spi_comm/deg_to_byte.py b/spi_comm/deg_to_byte.py
deleted file mode 100644
index 196d4a5..0000000
--- a/spi_comm/deg_to_byte.py
+++ /dev/null
@@ -1,5 +0,0 @@
-deg = 40
-sbinary = format(deg, 'b')
-print(sbinary)
-binary = "".join(("01", sbinary))
-print(binary) \ No newline at end of file
diff --git a/spi_comm/openmv_slave/spi_com_master.py b/spi_comm/openmv_slave/spi_com_master.py
deleted file mode 100644
index 6e10881..0000000
--- a/spi_comm/openmv_slave/spi_com_master.py
+++ /dev/null
@@ -1,36 +0,0 @@
-from machine import SPI, Pin
-deg = 40
-binary = format(deg, 'b')
-print(binary)
-
-spi = SPI(0, baudrate=400000) # Create SPI peripheral 0 at frequency of 400kHz.
- # Depending on the use case, extra parameters may be required
- # to select the bus characteristics and/or pins to use.
-cs = Pin(4, mode=Pin.OUT, value=1) # Create chip-select on pin 4.
-
-try:
- cs(0) # Select peripheral.
- spi.write(b"12345678") # Write 8 bytes, and don't care about received data.
-finally:
- cs(1) # Deselect peripheral.
-
-try:
- cs(0) # Select peripheral.
- rxdata = spi.read(8, 0x42) # Read 8 bytes while writing 0x42 for each byte.
-finally:
- cs(1) # Deselect peripheral.
-
-rxdata = bytearray(8)
-try:
- cs(0) # Select peripheral.
- spi.readinto(rxdata, 0x42) # Read 8 bytes inplace while writing 0x42 for each byte.
-finally:
- cs(1) # Deselect peripheral.
-
-txdata = b"12345678"
-rxdata = bytearray(len(txdata))
-try:
- cs(0) # Select peripheral.
- spi.write_readinto(txdata, rxdata) # Simultaneously write and read bytes.
-finally:
- cs(1) # Deselect peripheral.