workshop:통신
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| workshop:통신 [2012/06/25 21:48] – 203.247.149.205 | workshop:통신 [2018/07/18 14:10] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | 칩간에 | + | IC와 통신 |
| - | ====== WS2801 ====== | + | * [[/UART]] |
| + | * [[/ | ||
| + | * [[/I2C]] | ||
| + | * [[/SPI]] | ||
| - | LED 드라이버 | + | 칩간에 통신을 |
| - | + | ||
| - | 회로도 | + | |
| - | {{http:// | + | |
| - | + | ||
| - | Time | + | |
| - | + | ||
| - | {{http:// | + | |
| - | + | ||
| - | < | + | |
| - | int SDI = 11; | + | |
| - | int CKI = 12; | + | |
| - | int ledPin = 13; // LED | + | |
| - | + | ||
| - | void setup() { | + | |
| - | pinMode(SDI, | + | |
| - | pinMode(CKI, | + | |
| - | pinMode(ledPin, | + | |
| - | + | ||
| - | // | + | |
| - | // | + | |
| - | } | + | |
| - | + | ||
| - | void loop() { | + | |
| - | delay(2000); | + | |
| - | + | ||
| - | while(1){ | + | |
| - | post_frame(0xFF0000); | + | |
| - | + | ||
| - | // CLK pin keeps low more than 500uS will make the WS2801 internal status register reset | + | |
| - | digitalWrite(CKI, | + | |
| - | delayMicroseconds(500); | + | |
| - | + | ||
| - | digitalWrite(ledPin, | + | |
| - | delay(250); | + | |
| - | digitalWrite(ledPin, | + | |
| - | delay(250); | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | // this_led_color값의 비트를 ws2801에 CKI에 맞추어 SDI를 밀어 넣는다. | + | |
| - | void post_frame (long this_led_color) { | + | |
| - | for(byte color_bit = 23 ; color_bit != 255 ; color_bit--) { | + | |
| - | // | + | |
| - | + | ||
| - | digitalWrite(CKI, | + | |
| - | + | ||
| - | long mask = 1L << color_bit; | + | |
| - | //The 1' | + | |
| - | + | ||
| - | if(this_led_color & mask) | + | |
| - | digitalWrite(SDI, | + | |
| - | else | + | |
| - | digitalWrite(SDI, | + | |
| - | + | ||
| - | digitalWrite(CKI, | + | |
| - | } | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | 여러개 보낼경우. 이어서 보낸다. | + | |
| - | < | + | |
| - | post_frame(0xFF0000); | + | |
| - | post_frame(0x00FF00); | + | |
| - | // CLK pin keeps low more than 500uS will make the WS2801 internal status register reset | + | |
| - | digitalWrite(CKI, | + | |
| - | delayMicroseconds(500); | + | |
| - | + | ||
| - | </ | + | |
| - | ====== I2C ====== | + | |
| - | I2C직렬 컴퓨터 버스주변기기를 연결하기 위해 사용된다. | + | |
| - | + | ||
| - | {{http:// | + | |
| - | + | ||
| - | 데이터와 클럭은 pull-up | + | |
| - | + | ||
| - | {{http:// | + | |
| - | + | ||
| - | Time | + | |
| - | + | ||
| - | {{http:// | + | |
| - | + | ||
| - | {{http:// | + | |
| - | + | ||
| - | 실제 | + | |
| - | 24LC256 | + | |
| - | + | ||
| - | arduino i2c 관련 핀 | + | |
| - | * Analog4 - SDA | + | |
| - | * Analog5 - SCL | + | |
| - | + | ||
| - | Time | + | |
| - | + | ||
| - | {{http:// | + | |
| - | + | ||
| - | < | + | |
| - | #include < | + | |
| - | + | ||
| - | void i2c_eeprom_write_byte( int deviceaddress, | + | |
| - | int rdata = data; | + | |
| - | + | ||
| - | Wire.beginTransmission(deviceaddress); | + | |
| - | Wire.write((int)(eeaddress >> 8)); // MSB | + | |
| - | Wire.write((int)(eeaddress & 0xFF)); // LSB | + | |
| - | Wire.write(rdata); | + | |
| - | Wire.endTransmission(); | + | |
| - | } | + | |
| - | + | ||
| - | void i2c_eeprom_write_page( int deviceaddress, | + | |
| - | Wire.beginTransmission(deviceaddress); | + | |
| - | Wire.write((int)(eeaddresspage >> 8)); // MSB | + | |
| - | Wire.write((int)(eeaddresspage & 0xFF)); // LSB | + | |
| - | + | ||
| - | byte c; | + | |
| - | for ( c = 0; c < length; c++) | + | |
| - | Wire.write(data[c]); | + | |
| - | + | ||
| - | Wire.endTransmission(); | + | |
| - | } | + | |
| - | + | ||
| - | byte i2c_eeprom_read_byte( int deviceaddress, | + | |
| - | byte rdata = 0xFF; | + | |
| - | + | ||
| - | // Wire.beginTransmission(deviceaddress); | + | |
| - | // Wire.write((int)(eeaddress >> 8)); // MSB | + | |
| - | // Wire.write((int)(eeaddress & 0xFF)); // LSB | + | |
| - | // Wire.endTransmission(); | + | |
| - | // Wire.requestFrom(deviceaddress, | + | |
| - | + | ||
| - | if (Wire.available()) rdata = Wire.read(); | + | |
| - | + | ||
| - | return rdata; | + | |
| - | } | + | |
| - | + | ||
| - | void setup() { | + | |
| - | char data[] = "hello world"; | + | |
| - | Wire.begin(); | + | |
| - | Serial.begin(9600); | + | |
| - | i2c_eeprom_write_page(0x50, | + | |
| - | + | ||
| - | delay(10); //add a small delay | + | |
| - | + | ||
| - | Serial.println(" | + | |
| - | } | + | |
| - | + | ||
| - | void loop() { | + | |
| - | int addr=0; //EEPROM Address 0 | + | |
| - | byte b = i2c_eeprom_read_byte(0x50, | + | |
| - | + | ||
| - | while (b!=0) { | + | |
| - | | + | |
| - | | + | |
| - | b = i2c_eeprom_read_byte(0x50, | + | |
| - | } | + | |
| - | + | ||
| - | Serial.println(" | + | |
| - | delay(2000); | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | + | ||
| - | master가 slave에 데이터를 보낸다. | + | |
| - | + | ||
| - | {{http:// | + | |
| - | + | ||
| - | master가 slave의 데이터를 읽는다. | + | |
| - | {{http:// | ||
workshop/통신.1340660937.txt.gz · Last modified: 2018/07/18 14:09 (external edit)