Copy off node 1 to behave node 2
Dependencies: mbed RF24Network RF24
isen32_board.h@8:5c8bf540ed8e, 2021-05-24 (annotated)
- Committer:
- Giamarchi
- Date:
- Mon May 24 13:39:15 2021 +0000
- Revision:
- 8:5c8bf540ed8e
- Parent:
- 7:1f768ebd2742
New version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Giamarchi | 5:48f3f58ebd13 | 1 | #include "mbed.h" |
Giamarchi | 5:48f3f58ebd13 | 2 | |
Giamarchi | 5:48f3f58ebd13 | 3 | // Nucleo Board associé à la carte ISEN |
Giamarchi | 5:48f3f58ebd13 | 4 | |
Giamarchi | 5:48f3f58ebd13 | 5 | DigitalOut Led1(LED1); // PA5 attention SPI CLK aussi |
Giamarchi | 5:48f3f58ebd13 | 6 | DigitalIn BTN_User(PC_13); |
Giamarchi | 5:48f3f58ebd13 | 7 | |
Giamarchi | 5:48f3f58ebd13 | 8 | // ISEN32 Board |
Giamarchi | 7:1f768ebd2742 | 9 | /* |
Giamarchi | 5:48f3f58ebd13 | 10 | DigitalOut L0(PB_1); // Dels, en sortie, reliée à PB1 |
Giamarchi | 5:48f3f58ebd13 | 11 | DigitalOut L1(PB_2); |
Giamarchi | 5:48f3f58ebd13 | 12 | DigitalOut L2(PB_10); |
Giamarchi | 5:48f3f58ebd13 | 13 | DigitalOut L3(PB_11); |
Giamarchi | 5:48f3f58ebd13 | 14 | DigitalOut L4(PB_12); |
Giamarchi | 5:48f3f58ebd13 | 15 | DigitalOut L5(PB_13); |
Giamarchi | 5:48f3f58ebd13 | 16 | DigitalOut L6(PB_14); |
Giamarchi | 5:48f3f58ebd13 | 17 | DigitalOut L7(PB_15); // la plus à gauche |
Giamarchi | 7:1f768ebd2742 | 18 | */ |
Giamarchi | 5:48f3f58ebd13 | 19 | DigitalIn BTN1(PA_11); // Bouton Poussoir, en entrée, relié à PA11 |
Giamarchi | 6:6a3d4e0f6799 | 20 | DigitalIn BTN2(PA_12); |
Giamarchi | 6:6a3d4e0f6799 | 21 | DigitalIn BTN3(PC_6); |
Giamarchi | 6:6a3d4e0f6799 | 22 | DigitalIn BTN4(PC_5); |
Giamarchi | 5:48f3f58ebd13 | 23 | |
Giamarchi | 6:6a3d4e0f6799 | 24 | DigitalOut BZ1(PC_7); // Buzzer, en sortie, relié à PC7 |
Giamarchi | 5:48f3f58ebd13 | 25 | |
Giamarchi | 5:48f3f58ebd13 | 26 | //DigitalOut M1(PB_4); // Moteur mini, en sortie, relié à PB4 |
Giamarchi | 5:48f3f58ebd13 | 27 | //PwmOut M1(PB_4); // Moteur mini en mode PWM |
Giamarchi | 5:48f3f58ebd13 | 28 | |
Giamarchi | 5:48f3f58ebd13 | 29 | // Lignes pour entrées analogiques |
Giamarchi | 5:48f3f58ebd13 | 30 | AnalogIn RV1(A0); // RV1, en entrée analogique, relié à PA0 |
Giamarchi | 5:48f3f58ebd13 | 31 | AnalogIn RV2(A1); // RV2, en entrée analogique, relié à PA1 |
Giamarchi | 5:48f3f58ebd13 | 32 | AnalogIn SENSOR(A4); // Pour capteur externe, exemple capt. de temp. MCP9700 Attention en conflit possible avec DAC |
Giamarchi | 5:48f3f58ebd13 | 33 | |
Giamarchi | 5:48f3f58ebd13 | 34 | // Lignes SPI pour piloter le MAX7219 |
Giamarchi | 5:48f3f58ebd13 | 35 | SPI spi(PA_7, PA_6, PA_5); |
Giamarchi | 5:48f3f58ebd13 | 36 | DigitalOut CS(PA_8); |
Giamarchi | 5:48f3f58ebd13 | 37 | |
Giamarchi | 5:48f3f58ebd13 | 38 | // Lignes I2C |
Giamarchi | 6:6a3d4e0f6799 | 39 | DigitalOut SCL(PB_6); |
Giamarchi | 6:6a3d4e0f6799 | 40 | DigitalOut SDA(PB_7); |
Giamarchi | 5:48f3f58ebd13 | 41 | |
Giamarchi | 5:48f3f58ebd13 | 42 | // Adresses des 2 EEPROMs I2C |
Giamarchi | 5:48f3f58ebd13 | 43 | #define EEPROM1 0b1010000 |
Giamarchi | 5:48f3f58ebd13 | 44 | #define EEPROM2 0b1010001 |
Giamarchi | 5:48f3f58ebd13 | 45 | |
Giamarchi | 5:48f3f58ebd13 | 46 | // Lignes pour piloter des servomoteurs |
Giamarchi | 5:48f3f58ebd13 | 47 | //DigitalOut SERVO1(PB_9); |
Giamarchi | 5:48f3f58ebd13 | 48 | //DigitalOut SERVO2(PB_8); |
Giamarchi | 5:48f3f58ebd13 | 49 | //DigitalOut SERVO3(PC_8); |
Giamarchi | 5:48f3f58ebd13 | 50 | //DigitalOut SERVO4(PC_9); |
Giamarchi | 5:48f3f58ebd13 | 51 | |
Giamarchi | 5:48f3f58ebd13 | 52 | // Lignes pour piloter 2 moteurs DC |
Giamarchi | 5:48f3f58ebd13 | 53 | //DigitalOut EN1(PB_10); |
Giamarchi | 5:48f3f58ebd13 | 54 | //PwmOut EN1(PB_10); |
Giamarchi | 5:48f3f58ebd13 | 55 | //DigitalOut IN1(PB_1); |
Giamarchi | 5:48f3f58ebd13 | 56 | //DigitalOut IN2(PB_2); |
Giamarchi | 7:1f768ebd2742 | 57 | /* |
Giamarchi | 5:48f3f58ebd13 | 58 | void Set_8Dels(uint8_t position) |
Giamarchi | 5:48f3f58ebd13 | 59 | { |
Giamarchi | 5:48f3f58ebd13 | 60 | L0 = position & 0x01; |
Giamarchi | 5:48f3f58ebd13 | 61 | L1 = position & 0x02; |
Giamarchi | 5:48f3f58ebd13 | 62 | L2 = position & 0x04; |
Giamarchi | 5:48f3f58ebd13 | 63 | L3 = position & 0x08; |
Giamarchi | 5:48f3f58ebd13 | 64 | L4 = position & 0x10; |
Giamarchi | 5:48f3f58ebd13 | 65 | L5 = position & 0x20; |
Giamarchi | 5:48f3f58ebd13 | 66 | L6 = position & 0x40; |
Giamarchi | 5:48f3f58ebd13 | 67 | L7 = position & 0x80; |
Giamarchi | 5:48f3f58ebd13 | 68 | } |
Giamarchi | 7:1f768ebd2742 | 69 | */ |
Giamarchi | 5:48f3f58ebd13 | 70 | /* MAX7219 : Interface SPI pour afficheur 7 segments */ |
Giamarchi | 8:5c8bf540ed8e | 71 | void Init_Spi(void) |
Giamarchi | 5:48f3f58ebd13 | 72 | { |
Giamarchi | 5:48f3f58ebd13 | 73 | spi.format(16,3); // SPI en mode 16 bits |
Giamarchi | 5:48f3f58ebd13 | 74 | |
Giamarchi | 5:48f3f58ebd13 | 75 | CS = 0; |
Giamarchi | 5:48f3f58ebd13 | 76 | // spi.write(0x0F01); // Test Display On |
Giamarchi | 5:48f3f58ebd13 | 77 | // spi.write(0x0F00); // Test Display Off |
Giamarchi | 5:48f3f58ebd13 | 78 | spi.write(0x0C01); |
Giamarchi | 5:48f3f58ebd13 | 79 | CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 80 | |
Giamarchi | 5:48f3f58ebd13 | 81 | CS = 0; |
Giamarchi | 5:48f3f58ebd13 | 82 | spi.write(0x090F); // Mode BCD sur 4 digits |
Giamarchi | 5:48f3f58ebd13 | 83 | CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 84 | |
Giamarchi | 5:48f3f58ebd13 | 85 | CS = 0; |
Giamarchi | 8:5c8bf540ed8e | 86 | spi.write(0x0A01); // Intensité à 1/15 |
Giamarchi | 5:48f3f58ebd13 | 87 | CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 88 | |
Giamarchi | 5:48f3f58ebd13 | 89 | CS = 0; |
Giamarchi | 5:48f3f58ebd13 | 90 | spi.write(0x0B03); |
Giamarchi | 5:48f3f58ebd13 | 91 | CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 92 | |
Giamarchi | 5:48f3f58ebd13 | 93 | // CS = 0; |
Giamarchi | 5:48f3f58ebd13 | 94 | // spi.write(0x0F01); |
Giamarchi | 5:48f3f58ebd13 | 95 | // CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 96 | // wait_ms(1000); |
Giamarchi | 5:48f3f58ebd13 | 97 | CS = 0; |
Giamarchi | 5:48f3f58ebd13 | 98 | spi.write(0x0F00); // Test mode Off |
Giamarchi | 5:48f3f58ebd13 | 99 | CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 100 | |
Giamarchi | 5:48f3f58ebd13 | 101 | CS = 0; |
Giamarchi | 5:48f3f58ebd13 | 102 | spi.write(0x0101); // Chiffre des milliers |
Giamarchi | 5:48f3f58ebd13 | 103 | CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 104 | CS = 0; |
Giamarchi | 5:48f3f58ebd13 | 105 | spi.write(0x0282); // Chiffre des centaines |
Giamarchi | 5:48f3f58ebd13 | 106 | CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 107 | CS = 0; |
Giamarchi | 5:48f3f58ebd13 | 108 | spi.write(0x0303); // Chiffre des dizaines |
Giamarchi | 5:48f3f58ebd13 | 109 | CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 110 | CS = 0; |
Giamarchi | 5:48f3f58ebd13 | 111 | spi.write(0x0404); // Chiffre des unités |
Giamarchi | 5:48f3f58ebd13 | 112 | CS = 1; |
Giamarchi | 5:48f3f58ebd13 | 113 | } |
Giamarchi | 8:5c8bf540ed8e | 114 | |
Giamarchi | 8:5c8bf540ed8e | 115 | void Affiche_Display(uint16_t valeur) |
Giamarchi | 8:5c8bf540ed8e | 116 | { |
Giamarchi | 8:5c8bf540ed8e | 117 | uint8_t ch_4, ch_3, ch_2, ch_1; |
Giamarchi | 8:5c8bf540ed8e | 118 | |
Giamarchi | 8:5c8bf540ed8e | 119 | ch_4 = valeur/1000; |
Giamarchi | 8:5c8bf540ed8e | 120 | valeur = valeur - ch_4*1000; |
Giamarchi | 8:5c8bf540ed8e | 121 | ch_3 = valeur/100; |
Giamarchi | 8:5c8bf540ed8e | 122 | valeur = valeur - ch_3*100; |
Giamarchi | 8:5c8bf540ed8e | 123 | ch_2 = (valeur/10); |
Giamarchi | 8:5c8bf540ed8e | 124 | valeur = valeur - ch_2*10; |
Giamarchi | 8:5c8bf540ed8e | 125 | ch_1 = valeur; |
Giamarchi | 8:5c8bf540ed8e | 126 | |
Giamarchi | 8:5c8bf540ed8e | 127 | CS = 0; |
Giamarchi | 8:5c8bf540ed8e | 128 | spi.write(0x0100 | ch_4); // Chiffre des milliers |
Giamarchi | 8:5c8bf540ed8e | 129 | CS = 1; |
Giamarchi | 8:5c8bf540ed8e | 130 | CS = 0; |
Giamarchi | 8:5c8bf540ed8e | 131 | spi.write(0x0280 | ch_3); // Chiffre des centaines avec le point (8) |
Giamarchi | 8:5c8bf540ed8e | 132 | CS = 1; |
Giamarchi | 8:5c8bf540ed8e | 133 | CS = 0; |
Giamarchi | 8:5c8bf540ed8e | 134 | spi.write(0x0300 | ch_2); // Chiffre des dizaines |
Giamarchi | 8:5c8bf540ed8e | 135 | CS = 1; |
Giamarchi | 8:5c8bf540ed8e | 136 | CS = 0; |
Giamarchi | 8:5c8bf540ed8e | 137 | spi.write(0x0400 | ch_1); // Chiffre des unités |
Giamarchi | 8:5c8bf540ed8e | 138 | CS = 1; |
Giamarchi | 8:5c8bf540ed8e | 139 | } |