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.
Dependencies: max32625pico maxim-dev mbed-rtos USBDevice
Fork of PICO_USB_I2C_SPI by
main.cpp@20:166e033d5073, 2017-12-30 (annotated)
- Committer:
- seanburford
- Date:
- Sat Dec 30 05:31:11 2017 +0000
- Revision:
- 20:166e033d5073
- Parent:
- 19:1a13f0c067b1
Start SWIN voltage measurement with startBatV()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:60a522ae2e35 | 1 | #include "mbed.h" |
switches | 3:aa55728c8e09 | 2 | |
seanburford | 14:7a4b0f9d1474 | 3 | #include "max32625pico.h" |
seanburford | 20:166e033d5073 | 4 | #include "max14750.h" |
switches | 5:2436ae0a9eb1 | 5 | |
seanburford | 17:43cc59f768af | 6 | #include "USBSerial.h" |
seanburford | 17:43cc59f768af | 7 | USBSerial serial; |
seanburford | 17:43cc59f768af | 8 | |
seanburford | 14:7a4b0f9d1474 | 9 | static DigitalOut rLED(LED1); |
seanburford | 14:7a4b0f9d1474 | 10 | static DigitalOut gLED(LED2); |
seanburford | 14:7a4b0f9d1474 | 11 | static DigitalOut bLED(LED3); |
switches | 5:2436ae0a9eb1 | 12 | |
seanburford | 15:9801f08ce0ee | 13 | |
seanburford | 20:166e033d5073 | 14 | void readMax14750Regs(MAX14750* max14750) { |
seanburford | 20:166e033d5073 | 15 | char regs[0x20] = {}; |
seanburford | 20:166e033d5073 | 16 | if (max14750->readRegs(regs) != E_NO_ERROR) return; |
seanburford | 20:166e033d5073 | 17 | for (int i = 0; i < 32; i++) { |
seanburford | 20:166e033d5073 | 18 | serial.printf("%02X:%02X ", i, (int)regs[i]); |
seanburford | 17:43cc59f768af | 19 | } |
seanburford | 17:43cc59f768af | 20 | serial.printf("\r\n"); |
seanburford | 20:166e033d5073 | 21 | MAX14750::chip_t chipType = max14750->identify(regs); |
seanburford | 20:166e033d5073 | 22 | switch(chipType) { |
seanburford | 20:166e033d5073 | 23 | case MAX14750::MAX14750A: serial.printf("MAX14750A\r\n"); break; |
seanburford | 20:166e033d5073 | 24 | case MAX14750::MAX14750B: serial.printf("MAX14750B\r\n"); break; |
seanburford | 20:166e033d5073 | 25 | case MAX14750::MAX14750C: serial.printf("MAX14750C\r\n"); break; |
seanburford | 20:166e033d5073 | 26 | case MAX14750::MAX14720A: serial.printf("MAX14720A\r\n"); break; |
seanburford | 20:166e033d5073 | 27 | case MAX14750::MAX14720B: serial.printf("MAX14720B\r\n"); break; |
seanburford | 20:166e033d5073 | 28 | case MAX14750::MAX14720C: serial.printf("MAX14720C\r\n"); break; |
seanburford | 20:166e033d5073 | 29 | case MAX14750::MAX14720D: serial.printf("MAX14720D\r\n"); break; |
seanburford | 17:43cc59f768af | 30 | } |
seanburford | 20:166e033d5073 | 31 | if ((chipType == MAX14750::MAX14750A) || |
seanburford | 20:166e033d5073 | 32 | (chipType == MAX14750::MAX14750B) || |
seanburford | 20:166e033d5073 | 33 | (chipType == MAX14750::MAX14750C)) { |
seanburford | 17:43cc59f768af | 34 | serial.printf("SWIN: %s\r\n", regs[0x1B] & 8? "high": "low"); |
seanburford | 17:43cc59f768af | 35 | serial.printf("HVEN: %s\r\n", regs[0x1B] & 4? "high": "low"); |
seanburford | 17:43cc59f768af | 36 | serial.printf("BEN: %s\r\n", regs[0x1B] & 2? "high": "low"); |
seanburford | 17:43cc59f768af | 37 | serial.printf("LEN: %s\r\n", regs[0x1B] & 1? "high": "low"); |
seanburford | 17:43cc59f768af | 38 | } |
seanburford | 17:43cc59f768af | 39 | } |
seanburford | 17:43cc59f768af | 40 | |
switches | 0:60a522ae2e35 | 41 | int main() |
switches | 0:60a522ae2e35 | 42 | { |
switches | 2:57500e991166 | 43 | rLED = LED_ON; |
switches | 2:57500e991166 | 44 | gLED = LED_ON; |
switches | 2:57500e991166 | 45 | bLED = LED_OFF; |
switches | 3:aa55728c8e09 | 46 | |
seanburford | 14:7a4b0f9d1474 | 47 | MAX32625PICO pico( |
seanburford | 14:7a4b0f9d1474 | 48 | MAX32625PICO::IOH_3V3, MAX32625PICO::VIO_IOH, MAX32625PICO::VIO_IOH); |
switches | 0:60a522ae2e35 | 49 | |
seanburford | 20:166e033d5073 | 50 | MAX14750 max14750; |
seanburford | 20:166e033d5073 | 51 | max14750.init(P3_4, P3_5); |
switches | 2:57500e991166 | 52 | |
switches | 2:57500e991166 | 53 | rLED = LED_OFF; |
seanburford | 14:7a4b0f9d1474 | 54 | gLED = LED_OFF; |
switches | 5:2436ae0a9eb1 | 55 | |
switches | 1:6923b075c8d7 | 56 | while(1) { |
seanburford | 17:43cc59f768af | 57 | char c = serial.getc(); |
seanburford | 17:43cc59f768af | 58 | serial.printf("%c\r\n", c); |
seanburford | 20:166e033d5073 | 59 | if (c == 'v') { |
seanburford | 20:166e033d5073 | 60 | max14750.startBatV(); |
seanburford | 20:166e033d5073 | 61 | } else { |
seanburford | 20:166e033d5073 | 62 | readMax14750Regs(&max14750); |
seanburford | 20:166e033d5073 | 63 | } |
switches | 0:60a522ae2e35 | 64 | } |
seanburford | 16:847788f907eb | 65 | } |