ok
Dependencies: mbed ssd1306_library
Revision 6:d4fcbe0b2050, committed 2022-03-28
- Comitter:
- emmanueldavid
- Date:
- Mon Mar 28 06:25:02 2022 +0000
- Parent:
- 5:9c975d6bd219
- Commit message:
- ok
Changed in this revision
main_Carte1.cpp | Show diff for this revision Revisions of this file |
main_TP2.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 9c975d6bd219 -r d4fcbe0b2050 main_Carte1.cpp --- a/main_Carte1.cpp Wed Mar 10 18:20:16 2021 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,275 +0,0 @@ -/* - * Programme Carte 1 - * E. DAVID - Fevrier 2021 - */ - -#if !DEVICE_CAN -#error [NOT_SUPPORTED] CAN not supported for this target -#endif - -#include "mbed.h" -#include "ssd1306.h" -#include "stm32f3xx_hal_can.h" - -CAN_HandleTypeDef hcan1; - -typedef enum{ - DataFrame, - RemoteFrame, - ErrorFrame, - OverloadFrame -} TypeTrame; -TypeTrame Trame; - -SSD1306 OLED (I2C_SDA, I2C_SCL, 0x78); // assumes default I2C address of 0x78 -//SSD1306 OLED (I2C_SDA, I2C_SCL, 0x3C); // assumes default I2C address of 0x78 - -/* -typedef struct{ - can_id_t id; - Uchar ctrl; - Uchar * pt_donne; -} can_msg_t; -*/ - -DigitalOut ledD9(PA_4); -DigitalOut ledD8(PA_5); // Attention, désouder SB16&SB18 si utilisation I2c -DigitalOut ledD7(PA_6); -DigitalOut ledD6(PA_7); - -DigitalIn SW4_1(PA_1); -DigitalIn SW4_0(PA_3); -DigitalIn SW1(PB_4, PullUp); -DigitalIn SW2(PB_5, PullUp); -//DigitalIn SW3(PA_8, PullUp); - -//InterruptIn SW1(PB_4, PullUp); -//InterruptIn SW2(PB_5, PullUp); -InterruptIn SW3(PA_8, PullUp); - -AnalogIn adc_RV1(PA_0); -//Timer antirebond; - -CAN can(PA_11, PA_12); -Serial pc(USBTX, USBRX); - -int value_SW4; // valeur 0,1,2,3 - -char Reset[6] = "Reset"; -char Donnees[12]=""; -char Data[5] = "GEII"; -char DataArbitrage[5] = "K1bb"; -int Nb_messT = 0; -int Nb_messR = 0; - - -int detectionFrontSW1(void) { - int frontDescendant = 0; - static int etatPrecedent1=1; - int bp1 = SW1.read(); - if(bp1!=etatPrecedent1 && !bp1) - frontDescendant = 1; - etatPrecedent1= bp1; - return frontDescendant; -} - -int detectionFrontSW2(void) { - int frontDescendant = 0; - static int etatPrecedent2=1; - int bp2 = SW2.read(); - if(bp2!=etatPrecedent2 && !bp2) - frontDescendant = 1; - etatPrecedent2= bp2; - return frontDescendant; -} - -/* -int detectionFrontSW3(void) { - int frontDescendant = 0; - static int etatPrecedent1=1; - int bp = SW3.read(); - if(bp!=etatPrecedent1 && !bp) - frontDescendant = 1; - etatPrecedent1= bp; - return frontDescendant; -} -*/ - -/* Test Arbitrage */ -void AppuiSW3() { - if (value_SW4 == 3) { - if (can.write(CANMessage(60, DataArbitrage, 5 , CANData, CANStandard))) { // Rmq : tableau = pointeur - ledD8 = !ledD8; - Nb_messT++; - } - } -} - - -int LectureSW4(){ - int ETAT; - int value_SW4_0 = SW4_0.read(); - int value_SW4_1 = SW4_1.read(); - - if (value_SW4_1 == 1) { - if (value_SW4_0 == 1) - ETAT = 3; - else - ETAT = 2; - } - else { - if (value_SW4_0 == 1) - ETAT = 1; - else - ETAT = 0; - } - return ETAT; -} - -int main() { - //HAL_Init(); - - //uint8_t receivedMessage[8]; - //CAN_RxHeaderTypeDef RxHeader; - - //HAL_CAN_Start(&hcan); - - pc.baud(115200); - pc.printf("Affichage serie Carte 1 \n"); - - can.frequency(500000); - - CANMessage msg; - //unsigned char REC, TEC ; - - ledD6 = 1; ledD7 = 1; ledD8 = 1; ledD9 = 1; - - OLED.speed (SSD1306::Medium); // set working frequency - OLED.init(); // initialize SSD1306 - OLED.cls(); // clear frame buffer - /* - OLED.locate (0,0); // set text cursor to line 3, column 1 - OLED.printf ("GEII - Bus CAN"); // print to frame buffer - OLED.redraw(); // updates actual display transferring frame buffer over I2C bus - */ - //SW1.fall(&AppuiSW1); - SW3.fall(&AppuiSW3); - //antirebond.start(); - - OLED.locate (0,0); - OLED.printf ("NbRx = 0"); - OLED.locate (1,0); - OLED.printf ("NbTx = 0"); - - while(1) - { - value_SW4 = LectureSW4(); - - if (detectionFrontSW1()) - { - if (value_SW4 == 0) { - if (can.write(CANMessage(1975, Data, 5 , CANData, CANStandard))) { // Rmq : tableau = pointeur - ledD6 = !ledD6; - Nb_messT++; - } - } - } - if (detectionFrontSW2()) - { - if (value_SW4 == 0) { - if (can.write(CANMessage(1975, CANStandard))) { // Remote frame - ledD7 = !ledD7; - Nb_messT++; - } - } - } - /* - if (detectionFrontSW3()) - { - if (value_SW4 == 3) { - if (can.write(CANMessage(60, DataArbitrage, 5 , CANData, CANStandard))) { // Rmq : tableau = pointeur - ledD8 = !ledD8; - Nb_messT++; - } - } - } - */ - - if (can.read(msg)) { - Nb_messR++; - ledD9 = !ledD9; - for (int i =0; i < msg.len; i++) - Donnees[i] = msg.data[i]; - pc.printf("ID = 0x%.3x\r\n", msg.id); //ID sous forme 0x suivi de l'id - pc.printf("Length = %d\r\n", msg.len); - pc.printf("Boucle envoi CAN rderrors : %d, CAN tderrors : %d\n", can.rderror(), can.tderror()); - //REC = can.rderror(); - } - - OLED.locate (0,0); - OLED.printf ("NbRx = %d", Nb_messR); - OLED.locate (1,0); - OLED.printf ("NbTx = %d", Nb_messT); - OLED.locate (3,0); - OLED.printf ("Message recu "); - OLED.locate (4,0); - OLED.printf ("=> "); - OLED.puts(Donnees); - OLED.locate (6,0); - OLED.printf("Valeur REC=%u", can.rderror()); - OLED.locate (7,0); - OLED.printf("Valeur TEC=%u", can.tderror()); - OLED.redraw(); - wait(0.2); - } -} - - -/* Envoi d'une trame de requete */ -/* -void AppuiSW2() { - if (can.write(CANMessage(1620, CANStandard ))) { - ledD7 = !ledD7; - } -} -*/ - - - -/* Envoi d'une trame de donnees */ -/* -void AppuiSW1() { - if (antirebond.read_ms() > 100) - { - //while(!SW1); - if (value_SW4 == 1) - { - if (can.write(CANMessage(2021, Data, 5 , CANData, CANStandard))) // Rmq : tableau = pointeur - ledD6 = !ledD6; - } - antirebond.reset(); - } -} -*/ -/* -char *conversionIntChaine(int longueurChaine, int Valeur_int, char *ChaineAffichage) -{ - while (longueurChaine >= 0) - { - ChaineAffichage[longueurChaine] = (Valeur_int % 10) + 48; - Valeur_int /= 10; - longueurChaine--; - } - return (ChaineAffichage); -} -*/ - /* - OLED.locate (2,0); - OLED.printf("ADC A0=%2.1f", (adc_RV1.read()*100)); - OLED.locate (3,0); - OLED.printf("Valeur SW4_1=%d", SW4_0.read()); - OLED.locate (4,0); - OLED.printf("Valeur SW4_2=%d", SW4_1.read()); - OLED.locate (5,0); - OLED.printf("Valeur SW4=%d", value_SW4); - */ \ No newline at end of file
diff -r 9c975d6bd219 -r d4fcbe0b2050 main_TP2.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main_TP2.cpp Mon Mar 28 06:25:02 2022 +0000 @@ -0,0 +1,168 @@ +/* + * Programme principal TP2 - Bus CAN + */ + +#if !DEVICE_CAN +#error [NOT_SUPPORTED] CAN not supported for this target +#endif + +#include "mbed.h" +#include "ssd1306.h" + +SSD1306 OLED (I2C_SDA, I2C_SCL, 0x78); // assumes default I2C address of 0x78 + +DigitalOut ledD9(PA_4); +DigitalOut ledD8(PA_5); // Attention, désouder SB16&SB18 si utilisation I2c +DigitalOut ledD7(PA_6); +DigitalOut ledD6(PA_7); + +DigitalIn SW4_1(PA_1); +DigitalIn SW4_0(PA_3); +DigitalIn SW1(PB_4, PullUp); +DigitalIn SW2(PB_5, PullUp); + +InterruptIn SW3(PA_8, PullUp); + +AnalogIn adc_RV1(PA_0); + +CAN can(PA_11, PA_12); +Serial pc(USBTX, USBRX); + +int value_SW4; // valeur 0,1,2,3 + +char Reset[6] = "Reset"; +char Donnees[12]=""; +char Data[5] = "GEII"; +char DataArbitrage[5] = "K1bb"; +int Nb_messT = 0; +int Nb_messR = 0; + + +int detectionFrontSW1(void) { + int frontDescendant = 0; + static int etatPrecedent1=1; + int bp1 = SW1.read(); + if(bp1!=etatPrecedent1 && !bp1) + frontDescendant = 1; + etatPrecedent1= bp1; + return frontDescendant; +} + +int detectionFrontSW2(void) { + int frontDescendant = 0; + static int etatPrecedent2=1; + int bp2 = SW2.read(); + if(bp2!=etatPrecedent2 && !bp2) + frontDescendant = 1; + etatPrecedent2= bp2; + return frontDescendant; +} + +/* Test Arbitrage */ +void AppuiSW3() { + // if (value_SW4 == 3) { + if (can.write(CANMessage(60, DataArbitrage, 5 , CANData, CANStandard))) { // Rmq : tableau = pointeur + ledD8 = !ledD8; + Nb_messT++; + } + // } +} + + +int LectureSW4(){ + int ETAT; + int value_SW4_0 = SW4_0.read(); + int value_SW4_1 = SW4_1.read(); + + if (value_SW4_1 == 1) { + if (value_SW4_0 == 1) + ETAT = 3; + else + ETAT = 2; + } + else { + if (value_SW4_0 == 1) + ETAT = 1; + else + ETAT = 0; + } + return ETAT; +} + +int main() { + + //uint8_t receivedMessage[8]; + + pc.baud(115200); + pc.printf("Affichage serie Carte 1 \n"); + + can.frequency(500000); + + CANMessage msg; + //unsigned char REC, TEC ; + + ledD6 = 1; ledD7 = 1; ledD8 = 1; ledD9 = 1; + + OLED.speed (SSD1306::Medium); // set working frequency + OLED.init(); // initialize SSD1306 + OLED.cls(); // clear frame buffer + + SW3.fall(&AppuiSW3); // SW3 sous it + + + OLED.locate (0,0); + OLED.printf ("NbRx = 0"); + OLED.locate (1,0); + OLED.printf ("NbTx = 0"); + + while(1) + { + value_SW4 = LectureSW4(); + + if (detectionFrontSW1()) + { + if (value_SW4 == 0) { + if (can.write(CANMessage(1975, Data, 5 , CANData, CANStandard))) { // Rmq : tableau = pointeur + ledD6 = !ledD6; + Nb_messT++; + } + } + } + if (detectionFrontSW2()) + { + if (value_SW4 == 0) { + if (can.write(CANMessage(1975, CANStandard))) { // Remote frame + ledD7 = !ledD7; + Nb_messT++; + } + } + } + + if (can.read(msg)) { + Nb_messR++; + ledD9 = !ledD9; + for (int i =0; i < msg.len; i++) + Donnees[i] = msg.data[i]; + pc.printf("ID = 0x%.3x\r\n", msg.id); //ID sous forme 0x suivi de l'id + pc.printf("Length = %d\r\n", msg.len); + pc.printf("Boucle envoi CAN rderrors : %d, CAN tderrors : %d\n", can.rderror(), can.tderror()); + //REC = can.rderror(); + } + + OLED.locate (0,0); + OLED.printf ("NbRx = %d", Nb_messR); + OLED.locate (1,0); + OLED.printf ("NbTx = %d", Nb_messT); + OLED.locate (3,0); + OLED.printf ("Message recu "); + OLED.locate (4,0); + OLED.printf ("=> "); + OLED.puts(Donnees); + OLED.locate (6,0); + OLED.printf("Valeur REC=%u", can.rderror()); + OLED.locate (7,0); + OLED.printf("Valeur TEC=%u", can.tderror()); + OLED.redraw(); + wait(0.2); + } +} \ No newline at end of file