diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000000000000000000000000000000000..0cba2e6834fb66c3e0efef2684351d81ef47c4b3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "iostream": "cpp" + } +} \ No newline at end of file diff --git a/Makefile b/Makefile index f00e7fa78484e32f2fad2043d01d00646fe4b191..6f9c00de301f3c7e9598273287045b5148ffb2a6 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,9 @@ uart : compile_UART spi : compile_spi sudo ./spi +encoder : compile_encoder + sudo ./encoder + # compilations compile_switch : g++ -o switch switch.cpp -lwiringPi @@ -31,6 +34,9 @@ compile_UART : compile_spi : g++ -o spi spi.cpp -l wiringPi +compile_encoder : + g++ -o encoder encoder.cpp -l wiringPi + .PHONY : clean clean : - rm -rf switch motor led i2c uart spi + rm -rf switch motor led i2c uart spi encoder diff --git a/encoder.c b/encoder.cpp similarity index 74% rename from encoder.c rename to encoder.cpp index 2f64d28ecfbd085bb66434b20869e8a55722bce8..4415f02e9f7608a0cbdefc266ee7d87705c96679 100644 --- a/encoder.c +++ b/encoder.cpp @@ -1,8 +1,9 @@ -#include <stdio.h> #include <stdlib.h> - +#include <stdio.h> #include <wiringPi.h> +#include <wiringPiSPI.h> +/* const int MOSI_PIN = 12; //from RASPI to FPGA const int MISO_PIN = 13; //from RASPI to FPGA const int MOSI_PIN_FPGA = 14; //from RASPI to FPGA @@ -16,19 +17,36 @@ const int SCK_PIN = 14; //from RASPI to FPGA -> clock signal const int SCK_PIN_FPGA = 13; //from FPGA to ENCODER -> clock signal const int SS_PIN_2 = 11; //CE1 from RASPI to FPGA -> enable encoder const int CE1_PIN_FPGA = 15; +*/ + +unsigned char rawData[32]; +const int len = 32; +const int CHANNEL_DEO = 1; int main(int argc, char const *argv[]) { + int result, fd; + for (int i = 0; i<32; i++){ + rawData[i] = 0x01;} + if (wiringPiSetup() == -1) { printf("WiringPiSetup failed\n"); exit(EXIT_FAILURE); } + + fd = wiringPiSPISetup(CHANNEL_DEO, 500000); + result = wiringPiSPIDataRW(CHANNEL_DEO, rawData, len); + //read(wiringPiSPIGetFd (0), data, len); + for (int i = 0; i<32; i++){ + printf("speed: ", rawData[i], "\n"); + } + return 0; +/* pinMode(ENC_PIN_1A, INPUT); pinMode(ENC_PIN_1B, INPUT); pinMode(ENC_PIN_2A, INPUT); pinMode(ENC_PIN_2B, INPUT); - - return 0; -} \ No newline at end of file +*/ +} diff --git a/motor b/motor new file mode 100755 index 0000000000000000000000000000000000000000..3362d38843b55f93301e17d0e1e0810d601aeb94 Binary files /dev/null and b/motor differ diff --git a/spi b/spi new file mode 100755 index 0000000000000000000000000000000000000000..0f019bce4b79cf28883b6f2dae4dff47546dc392 Binary files /dev/null and b/spi differ diff --git a/spi.cpp b/spi.cpp index 36d0168a02f1b7c966dee6c14816235a1b0ad1af..8f4114b55bb303107a0f0208fe0a673336e2e209 100644 --- a/spi.cpp +++ b/spi.cpp @@ -13,14 +13,14 @@ int main(int argc, char const *argv[]) { int result, fd; unsigned char buff[30]; - + fd = wiringPiSPISetup(CHANNEL_CAN, 500000); if (fd == -1) { printf("Error setup\n"); exit(EXIT_FAILURE); } - - int reg = 0x42; + + int reg = 0x40; int GPIO[] = {0b00000001, 0b00000010, 0b00001000, 0b00010000}; buff[0] = reg; @@ -32,7 +32,7 @@ int main(int argc, char const *argv[]) buff[0] = reg; delay(1500); } - return 0; + }