Single UART with I2C-bus/SPI interface, 64 bytes of transmit and receive FIFOs, IrDA SIR built-in support
Dependencies: mbed
Revision 0:e35a417c6590, committed 2015-02-04
- Comitter:
- wataaki
- Date:
- Wed Feb 04 06:14:43 2015 +0000
- Commit message:
- Initial version
Changed in this revision
diff -r 000000000000 -r e35a417c6590 SC16IS750.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SC16IS750.cpp Wed Feb 04 06:14:43 2015 +0000 @@ -0,0 +1,105 @@ +#include "mbed.h" +#include "SC16IS750.h" + +I2C i2c(p28,p27); // sda, scl +Serial pc(USBTX, USBRX); // tx, rx +char cmd[128]; +char str[128]; +char i, j; + +void set_ch(char sel) +{ // PCA9541のサンプル + // MST_0側の自分にスレーブ側の制御権を得る場合 + cmd[0] = 1; // PCA9541 コマンドコード Cont Reg + i2c.write( 0xe2, cmd, 1); // Cont Regを指定 + i2c.read( 0xe2, cmd, 1); // Cont Regを読込み + wait(0.1); // 0.1s待つ + switch(cmd[0] & 0xf) + { + case 0: // bus off, has control + case 1: // bus off, no control + case 5: // bus on, no control + cmd[0] = 1; // PCA9541 コマンドコード Cont Reg + cmd[1] = 4; // bus on, has control + i2c.write( 0xe2, cmd, 2); // Cont Regにcmd[1]を書込み + i2c.read( 0xe2, cmd, 1); // Cont Regを読込み + break; + case 2: // bus off, no control + case 3: // bus off, has control + case 6: // bus on, no control + cmd[0] = 1; // PCA9541 コマンドコード Cont Reg + cmd[1] = 5; // bus on, has control + i2c.write( 0xe2, cmd, 2); // Cont Regにcmd[1]を書込み + i2c.read( 0xe2, cmd, 1); // Cont Regを読込み + break; + case 9: // bus on, no control + case 0xc: // bus on, no control + case 0xd: // bus off, no control + cmd[0] = 1; // PCA9541 コマンドコード Cont Reg + cmd[1] = 0; // bus on, has control + i2c.write( 0xe2, cmd, 2); // Cont Regにcmd[1]を書込み + i2c.read( 0xe2, cmd, 1); // Cont Regを読込み + break; + case 0xa: // bus on, no control + case 0xe: // bus off, no control + case 0xf: // bus on, has control + cmd[0] = 1; // PCA9541 コマンドコード Cont Reg + cmd[1] = 1; // bus on, has control + i2c.write( 0xe2, cmd, 2); // Cont Regにcmd[1]を書込み + i2c.read( 0xe2, cmd, 1); // Cont Regを読込み + break; + default: + break; + } + + cmd[0] = sel; // PCA9546 Cont Reg sel channel enabled + i2c.write( 0xe8, cmd, 1); // Send command string +} + +int main () +{ + i2c.frequency(100000); + pc.printf("\r\nSC16IS750 Sample Program\r\n"); + + set_ch(1); // SC16IS750はch0に接続 + // + + cmd[0] = LCR << 3; + cmd[1] = 0x83; // DLL,H Latch enable + i2c.write(SC16IS750_ADDR, cmd, 2); + + cmd[0] = DLL << 3; + cmd[1] = 117; // baud = 18e6 / 16 /117 = 9615 + i2c.write(SC16IS750_ADDR, cmd, 2); + + cmd[0] = DLH << 3; + cmd[1] = 0x0; + i2c.write(SC16IS750_ADDR, cmd, 2); + + cmd[0] = LCR << 3; + cmd[1] = 0x03; // NoParity 1Stop 8bits + i2c.write(SC16IS750_ADDR, cmd, 2); + + cmd[0] = FCR << 3; + cmd[1] = 0x07; // reset TX,RX FIFO, FIFO enable + i2c.write(SC16IS750_ADDR, cmd, 2); + + while(1) + { + pc.printf("\r\n文字列を入力してください>"); + pc.scanf("%s" , str); + j = strlen(str); + pc.printf("\r\n送信された文字列 = %s %d文字\r\n" , str, j); + cmd[0] = THR << 3; + for (i = 0; i < j; i++) cmd[i + 1] = str[i]; + i2c.write(SC16IS750_ADDR, cmd, j + 1); + + wait(1); + + cmd[0] = RHR << 3; // + i2c.write(SC16IS750_ADDR, cmd, 1, true); + i2c.read(SC16IS750_ADDR, cmd, j); + cmd[j] = 0; + pc.printf("受信した文字列 = %s\r\n", cmd); + } +} \ No newline at end of file
diff -r 000000000000 -r e35a417c6590 SC16IS750.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SC16IS750.h Wed Feb 04 06:14:43 2015 +0000 @@ -0,0 +1,29 @@ +// SC16IS750 I2C-UART +#define SC16IS750_ADDR 0x98 + +#define RHR 0x00 +#define THR 0x00 +#define IER 0x01 +#define IIR 0x02 +#define FCR 0x02 +#define LCR 0x03 +#define MCR 0x04 +#define LSR 0x05 +#define MSR 0x06 +#define SPR 0x07 +#define TCR 0x06 +#define TLR 0x07 +#define TXLVL 0x08 +#define RXLVL 0x09 +#define IODir 0x0a +#define IOState 0x0b +#define IOIntEna 0x0c +#define IOControl 0x0e +#define EFCR 0x0f +#define DLL 0x00 +#define DLH 0x01 +#define EFR 0x02 +#define XON1 0x04 +#define XON2 0x05 +#define XOFF1 0x06 +#define XOFF2 0x07
diff -r 000000000000 -r e35a417c6590 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Feb 04 06:14:43 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file