![](/media/cache/profiles/795c7a7a5ec6b460ec00c5841019b9e9.jpg.50x50_q85.jpg)
SC16IS750 TX sample
main.cpp@0:41dffa1b3405, 2012-07-17 (annotated)
- Committer:
- okano
- Date:
- Tue Jul 17 08:48:07 2012 +0000
- Revision:
- 0:41dffa1b3405
- Child:
- 1:40c636cb6d09
SC16IS750 TX sample: 1st version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:41dffa1b3405 | 1 | #include "mbed.h" |
okano | 0:41dffa1b3405 | 2 | |
okano | 0:41dffa1b3405 | 3 | I2C i2c( p28, p27 ); |
okano | 0:41dffa1b3405 | 4 | |
okano | 0:41dffa1b3405 | 5 | |
okano | 0:41dffa1b3405 | 6 | enum { |
okano | 0:41dffa1b3405 | 7 | RHR = 0x00 << 3, |
okano | 0:41dffa1b3405 | 8 | THR = 0x00 << 3, |
okano | 0:41dffa1b3405 | 9 | IER = 0x01 << 3, |
okano | 0:41dffa1b3405 | 10 | FCR = 0x02 << 3, |
okano | 0:41dffa1b3405 | 11 | IIR = 0x02 << 3, |
okano | 0:41dffa1b3405 | 12 | LCR = 0x03 << 3, |
okano | 0:41dffa1b3405 | 13 | MCR = 0x04 << 3, |
okano | 0:41dffa1b3405 | 14 | LSR = 0x05 << 3, |
okano | 0:41dffa1b3405 | 15 | MSR = 0x06 << 3, |
okano | 0:41dffa1b3405 | 16 | SPR = 0x07 << 3, |
okano | 0:41dffa1b3405 | 17 | TCR = 0x06 << 3, |
okano | 0:41dffa1b3405 | 18 | TLR = 0x07 << 3, |
okano | 0:41dffa1b3405 | 19 | TXLVL = 0x08 << 3, |
okano | 0:41dffa1b3405 | 20 | RXLVL = 0x09 << 3, |
okano | 0:41dffa1b3405 | 21 | IODir = 0x0A << 3, |
okano | 0:41dffa1b3405 | 22 | IOState = 0x0B << 3, |
okano | 0:41dffa1b3405 | 23 | IOIntEna = 0x0C << 3, |
okano | 0:41dffa1b3405 | 24 | reserved = 0x0D << 3, |
okano | 0:41dffa1b3405 | 25 | IOControl = 0x0E << 3, |
okano | 0:41dffa1b3405 | 26 | EFCR = 0x0F << 3, |
okano | 0:41dffa1b3405 | 27 | DLL = 0x00 << 3, |
okano | 0:41dffa1b3405 | 28 | DLH = 0x01 << 3, |
okano | 0:41dffa1b3405 | 29 | EFR = 0x02 << 3, |
okano | 0:41dffa1b3405 | 30 | XON1 = 0x04 << 3, |
okano | 0:41dffa1b3405 | 31 | XON2 = 0x05 << 3, |
okano | 0:41dffa1b3405 | 32 | XOFF1 = 0x06 << 3, |
okano | 0:41dffa1b3405 | 33 | XOFF2 = 0x07 << 3, |
okano | 0:41dffa1b3405 | 34 | }; |
okano | 0:41dffa1b3405 | 35 | |
okano | 0:41dffa1b3405 | 36 | #define ADDR 0x9A |
okano | 0:41dffa1b3405 | 37 | char three[] = { 0x03, 0xBF }; |
okano | 0:41dffa1b3405 | 38 | char data[] = { 0x0A, 0xBF }; |
okano | 0:41dffa1b3405 | 39 | |
okano | 0:41dffa1b3405 | 40 | #define N_OF_ACCESS 8 |
okano | 0:41dffa1b3405 | 41 | |
okano | 0:41dffa1b3405 | 42 | char init[ N_OF_ACCESS ][ 2 ] = { |
okano | 0:41dffa1b3405 | 43 | { LCR, 0x80 }, |
okano | 0:41dffa1b3405 | 44 | #ifdef BAUD_115200 |
okano | 0:41dffa1b3405 | 45 | { DLL, 0x0C }, |
okano | 0:41dffa1b3405 | 46 | { DLH, 0x00 }, |
okano | 0:41dffa1b3405 | 47 | #else |
okano | 0:41dffa1b3405 | 48 | { DLL, 0x60 }, // 9600 baud |
okano | 0:41dffa1b3405 | 49 | { DLH, 0x00 }, |
okano | 0:41dffa1b3405 | 50 | #endif |
okano | 0:41dffa1b3405 | 51 | { LCR, 0xBF }, |
okano | 0:41dffa1b3405 | 52 | { EFR, 0x10 }, |
okano | 0:41dffa1b3405 | 53 | { LCR, 0x03 }, |
okano | 0:41dffa1b3405 | 54 | { IER, 0x00 }, |
okano | 0:41dffa1b3405 | 55 | { FCR, 0x07 }, |
okano | 0:41dffa1b3405 | 56 | }; |
okano | 0:41dffa1b3405 | 57 | |
okano | 0:41dffa1b3405 | 58 | char *txt_data = "\x0NXP Semiconductors"; |
okano | 0:41dffa1b3405 | 59 | |
okano | 0:41dffa1b3405 | 60 | void init_registers( void ); |
okano | 0:41dffa1b3405 | 61 | void register_write( char address, char data ); |
okano | 0:41dffa1b3405 | 62 | char register_read( char address ); |
okano | 0:41dffa1b3405 | 63 | |
okano | 0:41dffa1b3405 | 64 | int main() { |
okano | 0:41dffa1b3405 | 65 | char r; |
okano | 0:41dffa1b3405 | 66 | |
okano | 0:41dffa1b3405 | 67 | init_registers(); |
okano | 0:41dffa1b3405 | 68 | |
okano | 0:41dffa1b3405 | 69 | #ifdef SINGLE_TX_BUFFER_WRITES |
okano | 0:41dffa1b3405 | 70 | txt_data++; |
okano | 0:41dffa1b3405 | 71 | for ( int i = 0; i < 18; i++ ) |
okano | 0:41dffa1b3405 | 72 | register_write( THR, *txt_data++ ); |
okano | 0:41dffa1b3405 | 73 | #else |
okano | 0:41dffa1b3405 | 74 | i2c.write( ADDR, txt_data, 19 ); |
okano | 0:41dffa1b3405 | 75 | #endif |
okano | 0:41dffa1b3405 | 76 | |
okano | 0:41dffa1b3405 | 77 | while ( 1 ) |
okano | 0:41dffa1b3405 | 78 | ; |
okano | 0:41dffa1b3405 | 79 | } |
okano | 0:41dffa1b3405 | 80 | |
okano | 0:41dffa1b3405 | 81 | void init_registers( void ) { |
okano | 0:41dffa1b3405 | 82 | for ( int i = 0; i < N_OF_ACCESS; i++ ) |
okano | 0:41dffa1b3405 | 83 | i2c.write( ADDR, init[ i ], 2 ); |
okano | 0:41dffa1b3405 | 84 | } |
okano | 0:41dffa1b3405 | 85 | |
okano | 0:41dffa1b3405 | 86 | void register_write( char address, char data ) { |
okano | 0:41dffa1b3405 | 87 | char w[ 2 ]; |
okano | 0:41dffa1b3405 | 88 | |
okano | 0:41dffa1b3405 | 89 | w[ 0 ] = address; |
okano | 0:41dffa1b3405 | 90 | w[ 1 ] = data; |
okano | 0:41dffa1b3405 | 91 | |
okano | 0:41dffa1b3405 | 92 | i2c.write( 0x9A, w, 2 ); |
okano | 0:41dffa1b3405 | 93 | } |
okano | 0:41dffa1b3405 | 94 | |
okano | 0:41dffa1b3405 | 95 | char register_read( char address ) { |
okano | 0:41dffa1b3405 | 96 | char r; |
okano | 0:41dffa1b3405 | 97 | |
okano | 0:41dffa1b3405 | 98 | i2c.write( 0x9A, &address, 1 ); |
okano | 0:41dffa1b3405 | 99 | i2c.read( 0x9A, &r, 1 ); |
okano | 0:41dffa1b3405 | 100 | |
okano | 0:41dffa1b3405 | 101 | return ( r ); |
okano | 0:41dffa1b3405 | 102 | } |