Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@3:4346e195ca2d, 2017-05-23 (annotated)
- Committer:
- Alex95
- Date:
- Tue May 23 10:19:02 2017 +0000
- Revision:
- 3:4346e195ca2d
- Parent:
- 2:931f44b24aa4
yoooooooooooooooooooooooooooooooooooooooooo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexis66 | 0:a291f7cc08f8 | 1 | #include "mbed.h" |
alexis66 | 0:a291f7cc08f8 | 2 | #include "rtos.h" |
Alex95 | 1:d940df294833 | 3 | #include "tHIH6130.h" |
alexis66 | 0:a291f7cc08f8 | 4 | |
alexis66 | 0:a291f7cc08f8 | 5 | #define SIG_RX_CAN 0x01 |
alexis66 | 0:a291f7cc08f8 | 6 | |
Alex95 | 1:d940df294833 | 7 | #define I2C_SDA p28 |
Alex95 | 1:d940df294833 | 8 | #define I2C_SCL p27 |
Alex95 | 1:d940df294833 | 9 | |
Alex95 | 1:d940df294833 | 10 | #define ADR_HIH 0x27 // adresse I2C réelle (sur 7 bits) |
Alex95 | 1:d940df294833 | 11 | |
Alex95 | 1:d940df294833 | 12 | I2C i2c(I2C_SDA , I2C_SCL ); |
alexis66 | 0:a291f7cc08f8 | 13 | |
alexis66 | 0:a291f7cc08f8 | 14 | DigitalOut led1(LED1); |
alexis66 | 0:a291f7cc08f8 | 15 | DigitalOut led2(LED2); |
alexis66 | 0:a291f7cc08f8 | 16 | |
alexis66 | 0:a291f7cc08f8 | 17 | Thread threadA; |
alexis66 | 0:a291f7cc08f8 | 18 | Thread threadB; |
alexis66 | 0:a291f7cc08f8 | 19 | |
alexis66 | 0:a291f7cc08f8 | 20 | |
alexis66 | 0:a291f7cc08f8 | 21 | CAN CanPort(p30, p29); |
alexis66 | 0:a291f7cc08f8 | 22 | CANMessage MessageRx; |
alexis66 | 0:a291f7cc08f8 | 23 | CANMessage MessageTx; |
Alex95 | 1:d940df294833 | 24 | tHIH6130 Capteur(ADR_HIH,&i2c); |
Alex95 | 1:d940df294833 | 25 | int flag=0; |
Alex95 | 1:d940df294833 | 26 | |
alexis66 | 0:a291f7cc08f8 | 27 | |
alexis66 | 0:a291f7cc08f8 | 28 | unsigned int Id; |
alexis66 | 0:a291f7cc08f8 | 29 | |
Alex95 | 1:d940df294833 | 30 | float mesureTemp(tHIH6130 Capteur) |
Alex95 | 1:d940df294833 | 31 | { |
Alex95 | 1:d940df294833 | 32 | Capteur.StartMesure(); |
Alex95 | 1:d940df294833 | 33 | wait_ms(50); |
Alex95 | 1:d940df294833 | 34 | Capteur.UpdateData(); |
Alex95 | 1:d940df294833 | 35 | float temp=Capteur.getTemp()/0.04; |
Alex95 | 1:d940df294833 | 36 | return temp; |
Alex95 | 1:d940df294833 | 37 | } |
Alex95 | 1:d940df294833 | 38 | |
Alex95 | 1:d940df294833 | 39 | float mesureHumi(tHIH6130 Capteur) |
Alex95 | 1:d940df294833 | 40 | { |
Alex95 | 1:d940df294833 | 41 | Capteur.StartMesure(); |
Alex95 | 1:d940df294833 | 42 | wait_ms(50); |
Alex95 | 1:d940df294833 | 43 | Capteur.UpdateData(); |
Alex95 | 1:d940df294833 | 44 | float humi=Capteur.getHumi()/0.025; |
Alex95 | 1:d940df294833 | 45 | return humi; |
Alex95 | 1:d940df294833 | 46 | } |
alexis66 | 0:a291f7cc08f8 | 47 | |
alexis66 | 0:a291f7cc08f8 | 48 | void canReader(void) |
alexis66 | 0:a291f7cc08f8 | 49 | { |
alexis66 | 0:a291f7cc08f8 | 50 | |
alexis66 | 0:a291f7cc08f8 | 51 | |
alexis66 | 0:a291f7cc08f8 | 52 | if (CanPort.read(MessageRx)) |
alexis66 | 0:a291f7cc08f8 | 53 | { |
alexis66 | 0:a291f7cc08f8 | 54 | led1 = !led1; |
alexis66 | 0:a291f7cc08f8 | 55 | threadA.signal_set(SIG_RX_CAN); |
alexis66 | 0:a291f7cc08f8 | 56 | } |
alexis66 | 0:a291f7cc08f8 | 57 | |
alexis66 | 0:a291f7cc08f8 | 58 | } |
alexis66 | 0:a291f7cc08f8 | 59 | |
alexis66 | 0:a291f7cc08f8 | 60 | |
alexis66 | 0:a291f7cc08f8 | 61 | void thA() |
alexis66 | 0:a291f7cc08f8 | 62 | { |
alexis66 | 0:a291f7cc08f8 | 63 | while(true) |
alexis66 | 0:a291f7cc08f8 | 64 | { |
alexis66 | 0:a291f7cc08f8 | 65 | Thread::signal_wait(SIG_RX_CAN); |
alexis66 | 0:a291f7cc08f8 | 66 | led2 = !led2; |
alexis66 | 0:a291f7cc08f8 | 67 | printf("RX FRAME ID = %X\n",MessageRx.id); |
alexis66 | 0:a291f7cc08f8 | 68 | |
alexis66 | 0:a291f7cc08f8 | 69 | } |
alexis66 | 0:a291f7cc08f8 | 70 | } |
alexis66 | 0:a291f7cc08f8 | 71 | |
alexis66 | 0:a291f7cc08f8 | 72 | void thB() |
alexis66 | 0:a291f7cc08f8 | 73 | { |
alexis66 | 0:a291f7cc08f8 | 74 | while (true) |
alexis66 | 0:a291f7cc08f8 | 75 | { |
alexis66 | 0:a291f7cc08f8 | 76 | led1 = !led1; |
Alex95 | 1:d940df294833 | 77 | printf("Envoi Temperature et Humidite \n"); |
alexis66 | 0:a291f7cc08f8 | 78 | MessageTx.id=Id; |
alexis66 | 0:a291f7cc08f8 | 79 | CanPort.write(MessageTx); |
alexis66 | 0:a291f7cc08f8 | 80 | wait(3); |
alexis66 | 0:a291f7cc08f8 | 81 | } |
alexis66 | 0:a291f7cc08f8 | 82 | } |
alexis66 | 0:a291f7cc08f8 | 83 | |
alexis66 | 0:a291f7cc08f8 | 84 | |
alexis66 | 0:a291f7cc08f8 | 85 | |
alexis66 | 0:a291f7cc08f8 | 86 | int main() |
alexis66 | 0:a291f7cc08f8 | 87 | { |
Alex95 | 1:d940df294833 | 88 | int temp=111; |
Alex95 | 1:d940df294833 | 89 | int humi=111; |
alexis66 | 0:a291f7cc08f8 | 90 | CanPort.frequency(20000); |
alexis66 | 0:a291f7cc08f8 | 91 | |
alexis66 | 0:a291f7cc08f8 | 92 | MessageTx.len=2; |
alexis66 | 0:a291f7cc08f8 | 93 | |
alexis66 | 0:a291f7cc08f8 | 94 | MessageTx.format = CANStandard; |
alexis66 | 0:a291f7cc08f8 | 95 | //MessageTx.format = CANExtended; |
alexis66 | 0:a291f7cc08f8 | 96 | |
alexis66 | 0:a291f7cc08f8 | 97 | MessageTx.type = CANData; |
alexis66 | 0:a291f7cc08f8 | 98 | //MessageTx.type = CANRemote; |
alexis66 | 0:a291f7cc08f8 | 99 | |
alexis66 | 0:a291f7cc08f8 | 100 | CanPort.attach(canReader,CAN::RxIrq); |
alexis66 | 0:a291f7cc08f8 | 101 | |
alexis66 | 0:a291f7cc08f8 | 102 | threadA.start(thA); |
alexis66 | 0:a291f7cc08f8 | 103 | threadB.start(thB); |
alexis66 | 0:a291f7cc08f8 | 104 | |
alexis66 | 0:a291f7cc08f8 | 105 | led1 = 0; |
alexis66 | 0:a291f7cc08f8 | 106 | printf("Start OK\n"); |
alexis66 | 0:a291f7cc08f8 | 107 | |
alexis66 | 0:a291f7cc08f8 | 108 | while (true) |
alexis66 | 0:a291f7cc08f8 | 109 | { |
Alex95 | 1:d940df294833 | 110 | if(flag==0) |
Alex95 | 1:d940df294833 | 111 | { |
Alex95 | 1:d940df294833 | 112 | temp=mesureTemp(Capteur); |
Alex95 | 1:d940df294833 | 113 | Id = 0x032; |
Alex95 | 1:d940df294833 | 114 | MessageTx.data[0]=temp/256; |
Alex95 | 1:d940df294833 | 115 | MessageTx.data[1]=temp%256; |
Alex95 | 1:d940df294833 | 116 | } |
Alex95 | 1:d940df294833 | 117 | else |
Alex95 | 1:d940df294833 | 118 | { |
Alex95 | 1:d940df294833 | 119 | humi=mesureHumi(Capteur); |
Alex95 | 1:d940df294833 | 120 | Id = 0x031; |
Alex95 | 1:d940df294833 | 121 | MessageTx.data[0]=humi/256; |
Alex95 | 1:d940df294833 | 122 | MessageTx.data[1]=humi%256; |
Alex95 | 1:d940df294833 | 123 | } |
Alex95 | 3:4346e195ca2d | 124 | flag=!flag; |
alexis66 | 0:a291f7cc08f8 | 125 | } |
alexis66 | 0:a291f7cc08f8 | 126 | } |