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@10:59582af3b94a, 2014-07-30 (annotated)
- Committer:
- EiJay
- Date:
- Wed Jul 30 09:05:10 2014 +0000
- Revision:
- 10:59582af3b94a
- Parent:
- 9:190ec4ad9ac7
- Child:
- 11:529d80511757
updates including just a single read eeprom;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EiJay | 0:7bb832ad2fb8 | 1 | #include "mbed.h" |
EiJay | 0:7bb832ad2fb8 | 2 | #include "MLX90393.h" |
EiJay | 4:dd534b0b54dd | 3 | |
EiJay | 0:7bb832ad2fb8 | 4 | |
EiJay | 0:7bb832ad2fb8 | 5 | int main() |
EiJay | 0:7bb832ad2fb8 | 6 | { |
EiJay | 5:92add1a06191 | 7 | //mBed indicators |
EiJay | 5:92add1a06191 | 8 | DigitalOut myled(LED1); |
EiJay | 5:92add1a06191 | 9 | |
EiJay | 5:92add1a06191 | 10 | //PC-communication |
EiJay | 5:92add1a06191 | 11 | Serial pc (USBTX, USBRX); |
EiJay | 5:92add1a06191 | 12 | pc.baud(9600); |
EiJay | 5:92add1a06191 | 13 | char hostCommand; |
EiJay | 7:7a91079a5ddd | 14 | int hostData1; |
EiJay | 7:7a91079a5ddd | 15 | int hostData2; |
EiJay | 7:7a91079a5ddd | 16 | int hostData3; |
EiJay | 5:92add1a06191 | 17 | //Chip communication |
EiJay | 5:92add1a06191 | 18 | SPI spi(p5, p6, p7); |
EiJay | 5:92add1a06191 | 19 | spi.format(MLX90393::spi_bits,MLX90393::spi_mode); |
EiJay | 5:92add1a06191 | 20 | spi.frequency(1000000); |
EiJay | 5:92add1a06191 | 21 | MLX90393 sensor(p26,&spi); |
EiJay | 0:7bb832ad2fb8 | 22 | |
EiJay | 2:ed31b405067c | 23 | |
EiJay | 5:92add1a06191 | 24 | //variables |
EiJay | 10:59582af3b94a | 25 | char read_buffer[11]; |
EiJay | 9:190ec4ad9ac7 | 26 | int content_buffer[63]; |
EiJay | 10:59582af3b94a | 27 | unsigned int dataInteger0; |
EiJay | 10:59582af3b94a | 28 | unsigned int dataInteger1; |
EiJay | 10:59582af3b94a | 29 | unsigned int dataInteger2; |
EiJay | 6:c09f0df4123c | 30 | //if you remove this line the program will fail |
EiJay | 7:7a91079a5ddd | 31 | //also make sure that you always send the status back to the host |
EiJay | 6:c09f0df4123c | 32 | hostCommand = 0; |
EiJay | 5:92add1a06191 | 33 | while(1) { |
EiJay | 5:92add1a06191 | 34 | pc.scanf(" %i, %i, %i, %i", &hostCommand, &hostData1, &hostData2, &hostData3); |
EiJay | 5:92add1a06191 | 35 | switch(hostCommand) { |
EiJay | 5:92add1a06191 | 36 | case 0: { |
EiJay | 10:59582af3b94a | 37 | //read eeprom |
EiJay | 10:59582af3b94a | 38 | sensor.RR(read_buffer,hostData1,hostData2); |
EiJay | 10:59582af3b94a | 39 | printf("%i\n",(read_buffer[0]*65536)+(read_buffer[1]*256) + read_buffer[2]); |
EiJay | 5:92add1a06191 | 40 | break; |
EiJay | 5:92add1a06191 | 41 | } |
EiJay | 5:92add1a06191 | 42 | case 1: { |
EiJay | 10:59582af3b94a | 43 | //read eeprom full |
EiJay | 9:190ec4ad9ac7 | 44 | for (int i = 0; i<63; i++) { |
EiJay | 9:190ec4ad9ac7 | 45 | sensor.RR(read_buffer,i,1); |
EiJay | 9:190ec4ad9ac7 | 46 | content_buffer[i] = (read_buffer[0]*65536)+(read_buffer[1]*256) + read_buffer[2]; |
EiJay | 9:190ec4ad9ac7 | 47 | } |
EiJay | 9:190ec4ad9ac7 | 48 | for (int i = 0; i<63; i++) { |
EiJay | 10:59582af3b94a | 49 | printf("%i\n",content_buffer[i]); |
EiJay | 9:190ec4ad9ac7 | 50 | } |
EiJay | 5:92add1a06191 | 51 | break; |
EiJay | 5:92add1a06191 | 52 | } |
EiJay | 5:92add1a06191 | 53 | case 2: { |
EiJay | 10:59582af3b94a | 54 | //Write register |
EiJay | 10:59582af3b94a | 55 | sensor.WR(read_buffer,hostData1,hostData2,hostData3); |
EiJay | 5:92add1a06191 | 56 | break; |
EiJay | 5:92add1a06191 | 57 | } |
EiJay | 5:92add1a06191 | 58 | case 3: { |
EiJay | 5:92add1a06191 | 59 | break; |
EiJay | 5:92add1a06191 | 60 | } |
EiJay | 5:92add1a06191 | 61 | case 4: { |
EiJay | 5:92add1a06191 | 62 | break; |
EiJay | 5:92add1a06191 | 63 | } |
EiJay | 5:92add1a06191 | 64 | case 5: { |
EiJay | 5:92add1a06191 | 65 | //exit |
EiJay | 5:92add1a06191 | 66 | sensor.EX(read_buffer,1); |
EiJay | 8:7f7c9353bc05 | 67 | printf("%i\n",read_buffer[0]); |
EiJay | 5:92add1a06191 | 68 | break; |
EiJay | 5:92add1a06191 | 69 | } |
EiJay | 5:92add1a06191 | 70 | case 6: { |
EiJay | 5:92add1a06191 | 71 | //single measurement |
EiJay | 10:59582af3b94a | 72 | sensor.SM(read_buffer,hostData1,hostData2); |
EiJay | 5:92add1a06191 | 73 | break; |
EiJay | 5:92add1a06191 | 74 | } |
EiJay | 5:92add1a06191 | 75 | case 7: { |
EiJay | 10:59582af3b94a | 76 | //read measurement |
EiJay | 10:59582af3b94a | 77 | sensor.RM(read_buffer,hostData1,hostData2); |
EiJay | 10:59582af3b94a | 78 | dataInteger0 = (read_buffer[0]<<24)+ (read_buffer[1]<<16)+(read_buffer[2]<<8)+read_buffer[3]; |
EiJay | 10:59582af3b94a | 79 | dataInteger1 = (read_buffer[4]<<24)+ (read_buffer[5]<<16)+(read_buffer[6]<<8)+read_buffer[7]; |
EiJay | 10:59582af3b94a | 80 | dataInteger2 = (read_buffer[8]<<16)+ (read_buffer[9]<<8)+read_buffer[10]; |
EiJay | 10:59582af3b94a | 81 | printf("%u,%u,%u\n",dataInteger0,dataInteger1,dataInteger2); |
EiJay | 5:92add1a06191 | 82 | break; |
EiJay | 5:92add1a06191 | 83 | } |
EiJay | 5:92add1a06191 | 84 | case 8: { |
EiJay | 5:92add1a06191 | 85 | //burst |
EiJay | 10:59582af3b94a | 86 | sensor.SB(read_buffer,hostData1,hostData2); |
EiJay | 8:7f7c9353bc05 | 87 | printf("%i\n",read_buffer[0]); |
EiJay | 5:92add1a06191 | 88 | break; |
EiJay | 5:92add1a06191 | 89 | } |
EiJay | 5:92add1a06191 | 90 | case 9: { |
EiJay | 5:92add1a06191 | 91 | //wake up on change |
EiJay | 5:92add1a06191 | 92 | sensor.SWOC(read_buffer,hostData1,1); |
EiJay | 8:7f7c9353bc05 | 93 | printf("%i\n",read_buffer[0]); |
EiJay | 5:92add1a06191 | 94 | break; |
EiJay | 5:92add1a06191 | 95 | } |
EiJay | 4:dd534b0b54dd | 96 | } |
EiJay | 0:7bb832ad2fb8 | 97 | } |
EiJay | 0:7bb832ad2fb8 | 98 | } |