Hey there, I have tried to make a program which can give me the data
from my sensor SI7006-20A with I2C. The problem is, that when I run my
project, nothing happens. I also used an Logic Analyzer and I saw that
nothing happened. I really don't know what I could change. Maybe someone
could help me, thanks a lot!
1 | #include "main.h"
|
2 | #include "msp430f5529.h"
|
3 |
|
4 | unsigned char add = 0x80; // serial number of the sensor
|
5 | unsigned char RHMeasure = 0xE5;
|
6 | unsigned char TEMpMeasure = 0xE0;
|
7 |
|
8 | double temp, rh;
|
9 | int help1, help2;
|
10 |
|
11 |
|
12 |
|
13 | void initI2C(){
|
14 | UCB0CTL1 |= UCSWRST;
|
15 | UCB1CTL0 = (1<<UCMST)|(1<<UCMODE0)|(1<<UCMODE1)|(1<<UCSYNC);
|
16 | UCB1CTL1=(1<<UCSSEL1)|(1<<UCTR);
|
17 | UCB1BR0 = 200;
|
18 | UCB1BR1 = 0;
|
19 | UCB1I2CSA = (add>>1);
|
20 | UCB1CTL1 &= ~(1<<UCSWRST);
|
21 | }
|
22 |
|
23 | void sendDataI2C(unsigned char data){
|
24 | UCB1CTL1|= (1<<UCTXSTT);
|
25 | UCB1TXBUF = data;
|
26 | while(UCB1IFG&(1<<UCTXIFG)==0x00);
|
27 | UCB1CTL1 |= (1<<UCB1IFG);
|
28 | }
|
29 |
|
30 | unsigned char readDataI2C(){
|
31 |
|
32 |
|
33 |
|
34 | }
|
35 |
|
36 | unsigned int startRead(){
|
37 | unsigned int data=0;
|
38 | UCB1CTL1&=~(0x10);
|
39 | UCB1CTL1 |=(1<<UCTXSTT);
|
40 | // while(UCB1CTL1 &(1<<UCTXSTT));
|
41 | if(UCB1CTL1 &(1<<UCTXSTT)){
|
42 | P1DIR |= BIT0;
|
43 | P1OUT |= BIT0;
|
44 | }else{
|
45 | P4DIR |= BIT7;
|
46 | P4OUT |= BIT7;
|
47 | }
|
48 | // while(UCB1STAT&(1<<UCBBUSY) > 0x00);
|
49 | while(UCB1IFG&(1<<UCRXIFG)==0x00);
|
50 | data = UCB1RXBUF*256;
|
51 |
|
52 | while(UCB1IFG&(1<<UCRXIFG)==0x00);
|
53 | data += UCB1RXBUF;
|
54 |
|
55 |
|
56 | UCB1CTL1 |= (1<<UCTXNACK);
|
57 | UCB1CTL1 |= (1<<UCTXSTP);
|
58 |
|
59 |
|
60 |
|
61 | }
|
62 |
|
63 | void startWrite(unsigned char cmd){
|
64 | UCB1CTL1|=(1<<UCTXSTT)|(0x10);
|
65 | //UCB1CTL1 |= (1<<UCTXSTP);
|
66 | UCB1TXBUF = cmd;
|
67 | while(UCB1IFG&(1<<UCTXIFG)==0x00);
|
68 |
|
69 |
|
70 |
|
71 | }
|
72 |
|
73 | int main(){
|
74 | WDTCTL = WDTPW + WDTHOLD;
|
75 | P4DIR |= BIT2;
|
76 | P4DIR |= BIT1;
|
77 | initI2C();
|
78 | while(1){
|
79 |
|
80 |
|
81 | startWrite(RHMeasure);
|
82 |
|
83 | /* help2 = startRead();
|
84 | rh = (help2*125)/65536-6;
|
85 |
|
86 | startWrite(TEMpMeasure);
|
87 | help1 = startRead();
|
88 | temp = (help1*175.72)/65536-46.85;
|
89 | */
|
90 | __delay_cycles(100);
|
91 |
|
92 | }
|
93 | }
|