zeshan_hyder@hotmail.com
Newbie level 3
- Joined
- Feb 14, 2014
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 34
hi all,
I am new to micro-controller projects. for my semester project, i want to interface atmega32 with SHT25 tempreture sensor through i2c protocol. i m using proteus ISIS for simulation before implementation.
i want to get tempreture readings from SHT25 and display the readings on portA in binary format. but my circuit and codes are not working and i dont know what is the problem.
code:
=====
I am new to micro-controller projects. for my semester project, i want to interface atmega32 with SHT25 tempreture sensor through i2c protocol. i m using proteus ISIS for simulation before implementation.
i want to get tempreture readings from SHT25 and display the readings on portA in binary format. but my circuit and codes are not working and i dont know what is the problem.
code:
=====
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 #include <inttypes.h> #include <avr/io.h> #include <avr/interrupt.h> #include <avr/sleep.h> #include <util/delay.h> void i2c_init (void) { TWSR = 0x00; TWBR = 0x47; TWCR = 0x04; } void i2c_start (void) { TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); while ((TWCR & (1<<TWINT)) == 0); } void i2c_write (unsigned char data) { TWDR = data; TWCR = (1 << TWINT) | (1 << TWEN); while ((TWCR & (1<<TWINT)) == 0); } unsigned char i2c_read (unsigned char isLast) { if (isLast == 0) TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWEA); else TWCR = (1<<TWINT) | (1<<TWEN); while ((TWCR & (1 << TWINT)) == 0); return TWDR; } void i2c_stop() { TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO); } int main() { unsigned char i = 0; DDRA = 0xFF; i2c_init(); i2c_start(); i2c_write(0b00000101); i=i2c_read(1); PORTA = 1; i2c_stop(); while(1); return 0; }
Attachments
Last edited by a moderator: