1 / 40

Embedded Systems Day-2

Embedded Systems Day-2. Sourabh Sankule. Schematic. Walk through Schematic. Understanding jumpers and NETs. 16x2 LCD Interfacing. Using Peter Fleury Library for AVRGCC. Configuring it for 16x2 LCD. Standard Functions : puts putchar etc Printing integer using itoa

rian
Download Presentation

Embedded Systems Day-2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Embedded SystemsDay-2 SourabhSankule

  2. Schematic • Walk through Schematic. • Understanding jumpers and NETs

  3. 16x2 LCD Interfacing • Using Peter Fleury Library for AVRGCC. • Configuring it for 16x2 LCD. • Standard Functions : puts putcharetc • Printing integer using itoa • Printing Float using dtostrf

  4. Peter Fleury Library http://www.jump.to/fleury

  5. Configuring #define LCD_PORT PORTC /**< port for the LCD lines */ #define LCD_DATA0_PORT LCD_PORT /**< port for 4bit data bit 0 */ #define LCD_DATA1_PORT LCD_PORT /**< port for 4bit data bit 1 */ #define LCD_DATA2_PORT LCD_PORT /**< port for 4bit data bit 2 */ #define LCD_DATA3_PORT LCD_PORT /**< port for 4bit data bit 3 */ #define LCD_DATA0_PIN 4 /**< pin for 4bit data bit 0 */ #define LCD_DATA1_PIN 5 /**< pin for 4bit data bit 1 */ #define LCD_DATA2_PIN 6 /**< pin for 4bit data bit 2 */ #define LCD_DATA3_PIN 7 /**< pin for 4bit data bit 3 */ #define LCD_RS_PORT LCD_PORT /**< port for RS line */ #define LCD_RS_PIN 0 /**< pin for RS line */ #define LCD_RW_PORT LCD_PORT /**< port for RW line */ #define LCD_RW_PIN 1 /**< pin for RW line */ #define LCD_E_PORT LCD_PORT /**< port for Enable line */ #define LCD_E_PIN 2 /**< pin for Enable line */

  6. LCD character locations x y

  7. First Code #include <stdlib.h> #include <avr/io.h> #include <avr/pgmspace.h> #include "lcd.h" int main(void) { lcd_init(LCD_DISP_ON);// Initialize LCD lcd_puts("SourabhSankule"); }

  8. Printing Integer <stdlib.h> itoa(intnum, char* buffer, int length) inti =12345; char buffer[10]; itoa(i, buffer,10); // Convert int i to buffer string lcd_puts(buffer);

  9. Printing FLoat dtostrf( … … .. .. ..) Find details in avrlibc manual and implement yourself.

  10. UART

  11. UART : Universal Asynchronous Receiver Transmitter • Hardware Pins • Packet formatand protocol • Parameters (baud rate, start bit, parity etc) • RS-232 vs UART / MAX232 / MAX3223 • FTDI 232and circuit • Using peter fleury libraryfor AVRGCC • putchar and getchar functions.

  12. Hardware TXD RXD GND Device-2 RXD TXD GND Device-1

  13. Data Packet Direction

  14. RS-232 Serial Port 1 : -2 to -12V 0 : +2 to +12V

  15. MAX-232 MAX-232 RS232 Data CMOS Data

  16. Circuit

  17. FTDI – FT232 FTDI FT232 UARTCMOS Data USB Data

  18. Circuit

  19. First code #include <stdlib.h> #include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #include "uart.h" /* 9600 baud */ #define UART_BAUD_RATE 9600 int main(void){ uart1_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU)); sei(); while(1){ uart1_putc('S'); _delay_ms(200); } }

  20. Dock-light

  21. I2CInter Integrated Circuit

  22. I2C • Hardware Pins. • Packet format and protocol. • Address of devices. • Reading TMP-275 high byte. • Reading TMP-275 both byte. • Configuring TMP-275 for 12 bit. • APDS lux measurement as assignment.

  23. Hardware SDA (serial data): Data transfer is done via this line SCL (serial clock): Used for the Synchronous Clock

  24. Data Packet

  25. Pointer Register Pointer First Write to Pointer Register. Second write to the Register to which Pointer Register Points. Read always from the Register to which Pointer Register Points. -> Cant Read Pointer Register Contents R/W Bit 0 for Write 1 for Read

  26. To Write 1. Send a start sequence 2. Send the I2C address of the slave with the R/W bit low (even address) 3. Send the internal register number you want to write to : first write to pointer register. 4. Send the data byte 5. [Optionally, send any further data bytes] 6. Send the stop sequence.

  27. To Read 1. Send a start sequence 2. Send I2C address with the R/W bit low (even address) to Write 3. Send Internal Register address of the Device which you want to read. 4. Send a start sequence again (repeated start) 5. Send I2C address with the R/W bit high (odd address) to Read 6. Read data byte from Device 7. Send the stop sequence. Default read is from the register to which pointer register points

  28. TMP-275 Read Datasheet for the configurations.

  29. Address of TMP-275 The TMP275 features three address pins allowing up to eight devices to be connected per bus.

  30. Pointer Register of TMP-275 Power-up reset value of P1/P0 is 00

  31. This register is used for configuring various modes of TMP-275 The Temperature Register of the TMP275 is a 12-bit, read-only register that stores the output of the most recent conversion.

  32. Temperature Format

  33. SHUTDOWN MODE (SD) The Shutdown Mode of the TMP275 allows the user to save maximum power by shutting down all device circuitry other than the serial interface, which reduces current consumption to typically less than 0.1μA. Shutdown Mode is enabled when the SD bit is 1; the device will shut down once the current conversion is completed. When SD is equal to 0, the device will maintain a continuous conversion state.

  34. Temperature Resolution (9-12 bit) The user can obtain 9, 10, 11, or 12 bits of resolution by addressing the Configuration Register and setting the resolution bits accordingly.

  35. Algorithm for Reading Temperature with 9 bit resolution • Send start sequence • Send Address (0b1001111) with R/W = 1 • Read byte 1 • Read byte 2 • Send stop sequence

  36. The Code i2c_start(0b10011111);// sending address and Read bit i = i2c_readAck(); j = i2c_readNak(); i2c_stop(); uart1_putc(i); uart1_putc(j); _delay_ms(500);

  37. Algorithm for Reading Temperature with 12 bit resolution • Send Start Sequence • Send Address (0b1001111) with R/W = 0 • Send byte = 0b01 : to point to config register • Send byte = 0b01100000 : to configure for 12 bit resolution mode. • Send stop sequence. • Send Start sequence • Send Address with R/W = 0 to write • Send byte = 0b00 : to point to temp register • Send Stop Sequence • Send Start Sequence • Send Address with R/W = 1 • Read high and low byte • Send Stop sequence

  38. The Code i2c_start(0b10011110); i2c_write(0b01);// to point to config register i2c_write(0b01100000); // for changing R1 and R0 for 12 bit resolution i2c_stop(); i2c_start(0b10011110); i2c_write(0b00);// to point back to temp register i2c_stop(); i2c_start(0b10011111);// sending address and Read bit i = i2c_readAck(); j = i2c_readNak(); i2c_stop();

  39. END

More Related