![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Publishing for sharing with Harald
test_mode.cpp@4:1c48c9fa44fc, 2020-05-22 (annotated)
- Committer:
- CactusSemi
- Date:
- Fri May 22 19:19:45 2020 +0000
- Revision:
- 4:1c48c9fa44fc
- Parent:
- 3:3e8c16b6620c
Publishing for sharing with Harald
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CactusSemi | 3:3e8c16b6620c | 1 | #include "mbed.h" |
CactusSemi | 3:3e8c16b6620c | 2 | |
CactusSemi | 3:3e8c16b6620c | 3 | extern Serial pc; |
CactusSemi | 3:3e8c16b6620c | 4 | |
CactusSemi | 3:3e8c16b6620c | 5 | |
CactusSemi | 3:3e8c16b6620c | 6 | char test_char = 0; |
CactusSemi | 3:3e8c16b6620c | 7 | int test = 1; |
CactusSemi | 3:3e8c16b6620c | 8 | |
CactusSemi | 3:3e8c16b6620c | 9 | void get_char() { |
CactusSemi | 3:3e8c16b6620c | 10 | test_char = pc.getc(); |
CactusSemi | 3:3e8c16b6620c | 11 | if(test_char == 's') test=0; |
CactusSemi | 3:3e8c16b6620c | 12 | pc.printf("\n\r"); |
CactusSemi | 3:3e8c16b6620c | 13 | } |
CactusSemi | 3:3e8c16b6620c | 14 | |
CactusSemi | 3:3e8c16b6620c | 15 | void testmode() { |
CactusSemi | 3:3e8c16b6620c | 16 | DigitalOut sda(p9,1); |
CactusSemi | 3:3e8c16b6620c | 17 | DigitalOut scl(p10,1); |
CactusSemi | 3:3e8c16b6620c | 18 | LPC_PINCON->PINMODE_OD0 = (LPC_PINCON->PINMODE_OD0 | 0x0003); // To make p9 & P10 open_drain |
CactusSemi | 3:3e8c16b6620c | 19 | Timer timer1; |
CactusSemi | 3:3e8c16b6620c | 20 | test = 1; |
CactusSemi | 3:3e8c16b6620c | 21 | test_char = 0; |
CactusSemi | 3:3e8c16b6620c | 22 | pc.printf("\n\n\r\tStarting test-mode pattern generation ...\n\r"); |
CactusSemi | 3:3e8c16b6620c | 23 | pc.printf("\n\n\r\tEnter 's' to stop test-mode: "); |
CactusSemi | 3:3e8c16b6620c | 24 | pc.attach(&get_char); //interupt looking for character entry |
CactusSemi | 3:3e8c16b6620c | 25 | timer1.start(); |
CactusSemi | 3:3e8c16b6620c | 26 | while(test) { |
CactusSemi | 3:3e8c16b6620c | 27 | while(timer1.read_us()<300) { |
CactusSemi | 3:3e8c16b6620c | 28 | } |
CactusSemi | 3:3e8c16b6620c | 29 | sda=0; |
CactusSemi | 3:3e8c16b6620c | 30 | while(timer1.read_us()<600) { |
CactusSemi | 3:3e8c16b6620c | 31 | } |
CactusSemi | 3:3e8c16b6620c | 32 | scl=0; |
CactusSemi | 3:3e8c16b6620c | 33 | while(timer1.read_us()<900) { |
CactusSemi | 3:3e8c16b6620c | 34 | } |
CactusSemi | 3:3e8c16b6620c | 35 | sda=1; |
CactusSemi | 3:3e8c16b6620c | 36 | while(timer1.read_us()<950) { |
CactusSemi | 3:3e8c16b6620c | 37 | } |
CactusSemi | 3:3e8c16b6620c | 38 | scl=1; |
CactusSemi | 3:3e8c16b6620c | 39 | while(timer1.read_us()<1200) { |
CactusSemi | 3:3e8c16b6620c | 40 | } |
CactusSemi | 3:3e8c16b6620c | 41 | timer1.reset(); |
CactusSemi | 3:3e8c16b6620c | 42 | } |
CactusSemi | 3:3e8c16b6620c | 43 | timer1.stop(); |
CactusSemi | 3:3e8c16b6620c | 44 | scl=1; |
CactusSemi | 3:3e8c16b6620c | 45 | sda=1; |
CactusSemi | 3:3e8c16b6620c | 46 | pc.printf("\n\n\r\t....test-mode pattern generation stopped\n\n\r"); |
CactusSemi | 3:3e8c16b6620c | 47 | sda.~DigitalOut(); |
CactusSemi | 3:3e8c16b6620c | 48 | scl.~DigitalOut(); |
CactusSemi | 3:3e8c16b6620c | 49 | pc.attach(NULL); |
CactusSemi | 3:3e8c16b6620c | 50 | return; |
CactusSemi | 3:3e8c16b6620c | 51 | } |