Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / pic16 / libio / i2c / i2cwrites.c
1
2 #include <pic18fregs.h>
3
4 #include <i2c.h>
5
6 char i2c_writestr(unsigned char *ptr)
7 {
8   while( *ptr ) {
9     if( SSPCON1bits.SSPM3 ) {
10       if(i2c_writechar( *ptr )) {
11         return (-3);
12       }
13       I2C_IDLE();
14       if( SSPCON2bits.ACKSTAT ) {
15         return (-2);
16       }
17     } else {
18       PIR1bits.SSPIF = 0;
19       SSPBUF = *ptr;
20       SSPCON1bits.CKP = 1;
21       while( !PIR1bits.SSPIF );
22       
23       if((!SSPSTATbits.R_W) && ( !SSPSTATbits.BF )) {
24         return (-2);
25       }
26     }
27     
28     ptr++;
29   }
30
31   return 0;
32 }