![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
FINAL PROJECT isn't it
Fork of ELEC351 by
main.cpp
- Committer:
- thomasmorris
- Date:
- 2018-05-07
- Revision:
- 53:71f59e195f06
- Parent:
- 52:99915f5240b2
- Child:
- 54:a4c5949707ca
File content as of revision 53:71f59e195f06:
#include "SETUP.hpp" int SPI_RX_DATA = 0; int Cubelet_Colours[9] = {0,0,0,0,0,0,0,0,0};//9 cubelets store colours here int Received_data = 0; bool Data_from_slave[16] = {0}; //Interrupt service routine for handling the timeout of SW1 void SW1TimeOutHandler() { SW1TimeOut.detach(); //Stop the timeout counter firing SW1.fall(&SW1FallingEdge); //Now wait for a falling edge } //Interrupt service routive for SW2 falling edge (release) void SW1FallingEdge() { SW1.fall(NULL); //Disable this interrupt SW1TimeOut.attach(&SW1TimeOutHandler, SW1_SW2_Timeout_Time); //Start timeout counter } //Interrupt service routine for handling the timeout of SW2 void SW2TimeOutHandler() { SW2TimeOut.detach(); //Stop the timeout counter firing SW2.fall(&SW2FallingEdge); //Now wait for a falling edge } //Interrupt service routive for SW2 falling edge (release) void SW2FallingEdge() { SW2.fall(NULL); //Disable this interrupt SW2TimeOut.attach(&SW2TimeOutHandler, SW1_SW2_Timeout_Time); //Start timeout counter } void LCD_Output() { while(1) { //Write to the LCD } } void Serial_Commands() { while(1) { Serial_Commands_Output(); //Enable Serial Commands } } void LED_Logging() { while(1) { Log_Leds(); //Flashes the yellow led to indicate the logging mode } } void SPI_INTERFACE() { //pc.printf("SPI Test \n"); Thread::wait(1000); while(1) { //Do stuff cs= 0; SPI_RX_DATA = spi.write(0xCB); wait_us(3); cs= 1; //SPI_RX_DATA = SPI_RX_DATA >> 7; //SPI_RX_DATA = SPI_RX_DATA << 1; //pc.printf("Received data : %x\n",SPI_RX_DATA); std::bitset<16> bits(SPI_RX_DATA); cout << bits << endl; pc.printf("Received data = %d\n", SPI_RX_DATA); //wait_us(3); Thread::wait(1000); } } void Motor_Control() { while(1) { if(Motor_To_Select !=0 and steps !=0) { if(Motor_To_Select == 1) { STEPPER_MOTOR_1.Rotate_Steps(steps ,direction); //Motor_To_Select = 0; } else if(Motor_To_Select == 2) { STEPPER_MOTOR_2.Rotate_Steps(steps ,direction); //Motor_To_Select = 0; } else if(Motor_To_Select == 3) { STEPPER_MOTOR_3.Rotate_Steps(steps ,direction); //Motor_To_Select = 0; } else if(Motor_To_Select == 4) { STEPPER_MOTOR_4.Rotate_Steps(steps ,direction); //Motor_To_Select = 0; } else if(Motor_To_Select == 5) { STEPPER_MOTOR_5.Rotate_Steps(steps ,direction); //Motor_To_Select = 0; } else if(Motor_To_Select == 6) { STEPPER_MOTOR_6.Rotate_Steps(steps ,direction); //Motor_To_Select = 0; } } } } int main() { set_time(1515530152); //Sets time pc.baud(9600); //Sets the Serial Comms Baud Rate //SPI_INIT(); cs = 1; //Active Low // Setup the spi for 8 bit data, high steady state clock, // second edge capture, with a 1MHz clock rate spi.format(16,1); // 8 Data bits phase 0 polarity 0 spi.frequency(1000000);//Output clock frequency 1Mhz //post(); //Power on Self Test //Start Threads t1.start(Motor_Control); t2.start(SPI_INTERFACE); t3.start(Serial_Commands); //Interrupts SW1.fall(&SW1FallingEdge); SW2.fall(&SW2FallingEdge); //Main thread ID idMain = osThreadGetId(); //CMSIS RTOS call //Thread ID id1 = t1.gettid(); id2 = t2.gettid(); id3 = t3.gettid(); id4 = t4.gettid(); id5 = t5.gettid(); id6 = t6.gettid(); while(true) { //Do nothing main thread will sleep } }