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: Adafruit-PWM-Servo-Driver MPU6050 RS300 mbed
SCI.cpp@12:6cd135bf03bd, 2013-02-03 (annotated)
- Committer:
- syundo0730
- Date:
- Sun Feb 03 04:53:44 2013 +0000
- Revision:
- 12:6cd135bf03bd
- Child:
- 13:711f74b2fa33
file reading, motion selecting, serial communication
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| syundo0730 | 12:6cd135bf03bd | 1 | #include "mbed.h" |
| syundo0730 | 12:6cd135bf03bd | 2 | #include "SCI.h" |
| syundo0730 | 12:6cd135bf03bd | 3 | |
| syundo0730 | 12:6cd135bf03bd | 4 | SCI::SCI(PinName tx, PinName rx) |
| syundo0730 | 12:6cd135bf03bd | 5 | { |
| syundo0730 | 12:6cd135bf03bd | 6 | serial = new Serial(tx, rx); |
| syundo0730 | 12:6cd135bf03bd | 7 | } |
| syundo0730 | 12:6cd135bf03bd | 8 | |
| syundo0730 | 12:6cd135bf03bd | 9 | SCI::~SCI() |
| syundo0730 | 12:6cd135bf03bd | 10 | { |
| syundo0730 | 12:6cd135bf03bd | 11 | delete serial; |
| syundo0730 | 12:6cd135bf03bd | 12 | } |
| syundo0730 | 12:6cd135bf03bd | 13 | |
| syundo0730 | 12:6cd135bf03bd | 14 | char SCI::getid() |
| syundo0730 | 12:6cd135bf03bd | 15 | { |
| syundo0730 | 12:6cd135bf03bd | 16 | char comm, id; |
| syundo0730 | 12:6cd135bf03bd | 17 | comm = getc_nowait(); |
| syundo0730 | 12:6cd135bf03bd | 18 | if (comm == 'A') { |
| syundo0730 | 12:6cd135bf03bd | 19 | serial->putc(comm); |
| syundo0730 | 12:6cd135bf03bd | 20 | serial->printf("command"); |
| syundo0730 | 12:6cd135bf03bd | 21 | id = getc_wait(); |
| syundo0730 | 12:6cd135bf03bd | 22 | } |
| syundo0730 | 12:6cd135bf03bd | 23 | return id; |
| syundo0730 | 12:6cd135bf03bd | 24 | } |
| syundo0730 | 12:6cd135bf03bd | 25 | |
| syundo0730 | 12:6cd135bf03bd | 26 | char SCI::getc_wait() |
| syundo0730 | 12:6cd135bf03bd | 27 | { |
| syundo0730 | 12:6cd135bf03bd | 28 | while (!serial->readable()) { |
| syundo0730 | 12:6cd135bf03bd | 29 | serial->printf("waiting.."); |
| syundo0730 | 12:6cd135bf03bd | 30 | } |
| syundo0730 | 12:6cd135bf03bd | 31 | return serial->getc(); |
| syundo0730 | 12:6cd135bf03bd | 32 | } |
| syundo0730 | 12:6cd135bf03bd | 33 | |
| syundo0730 | 12:6cd135bf03bd | 34 | char SCI::getc_nowait() |
| syundo0730 | 12:6cd135bf03bd | 35 | { |
| syundo0730 | 12:6cd135bf03bd | 36 | uint8_t buf = 0; |
| syundo0730 | 12:6cd135bf03bd | 37 | if (serial->readable()) { |
| syundo0730 | 12:6cd135bf03bd | 38 | buf = serial->getc(); |
| syundo0730 | 12:6cd135bf03bd | 39 | } |
| syundo0730 | 12:6cd135bf03bd | 40 | return buf; |
| syundo0730 | 12:6cd135bf03bd | 41 | } |
| syundo0730 | 12:6cd135bf03bd | 42 | |
| syundo0730 | 12:6cd135bf03bd | 43 | /*uint16_t readint(void) |
| syundo0730 | 12:6cd135bf03bd | 44 | { |
| syundo0730 | 12:6cd135bf03bd | 45 | uint8_t buff[16]; |
| syundo0730 | 12:6cd135bf03bd | 46 | buff[0] = pc->getc(); |
| syundo0730 | 12:6cd135bf03bd | 47 | buff[1] = pc->getc(); |
| syundo0730 | 12:6cd135bf03bd | 48 | uint16_t val; |
| syundo0730 | 12:6cd135bf03bd | 49 | val = (uint16_t)(buff[1] << 8) | (uint16_t)buff[0]; |
| syundo0730 | 12:6cd135bf03bd | 50 | return val; |
| syundo0730 | 12:6cd135bf03bd | 51 | } |
| syundo0730 | 12:6cd135bf03bd | 52 | |
| syundo0730 | 12:6cd135bf03bd | 53 | void sendint(uint16_t val) |
| syundo0730 | 12:6cd135bf03bd | 54 | { |
| syundo0730 | 12:6cd135bf03bd | 55 | uint8_t buff[16]; |
| syundo0730 | 12:6cd135bf03bd | 56 | buff[0] = (uint8_t)(val & 0x00FF); |
| syundo0730 | 12:6cd135bf03bd | 57 | buff[1] = (uint8_t)(val >> 8); |
| syundo0730 | 12:6cd135bf03bd | 58 | pc.putc(buff[0]); |
| syundo0730 | 12:6cd135bf03bd | 59 | pc.putc(buff[1]); |
| syundo0730 | 12:6cd135bf03bd | 60 | }*/ |