Esempio n. 1
0
File: sht.c Progetto: promovicz/rtos
static void sht_sendb(uint8_t cmd)
{
    uint8_t i;

    sda_output();

    for(i = 0; i < 8; i++) {
        scl_low();
        sda_set((cmd>>i)&1);
        scl_high();
    }

    scl_low();
    sda_input();
    printf("foo!\n");
    while(sda_get());
    scl_high();
    scl_low();

    printf("bar!\n");
    while(!sda_get());

    printf("bla!\n");
    i = 0;
    while(sda_get()) {
        i++;
        if(i == 255) break;

        usleep(10*1000);
    }
}
Esempio n. 2
0
File: sht.c Progetto: promovicz/rtos
static uint16_t sht_readw(void)
{
    uint8_t i;
    uint16_t r = 0;

    sda_input();

    for(i = 0; i < 8; i++) {
        scl_high();
        r |= sda_get()?(1<<i):0;
        scl_low();
    }

    sda_output();
    sda_set(0);
    scl_high();
    scl_low();
    sda_input();

    for(i = 8; i < 16; i++) {
        scl_high();
        r |= sda_get()?(1<<i):0;
        scl_low();
    }

    return r;
}
Esempio n. 3
0
static uint8_t getByte(const I2C_ABSTRACT_BUS* bus, boolean isLastByte){
	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)bus;
	int8_t i;
	uint8_t b = 0;

	sda_high(i2c);
	for(i=7; i>=0; i--){
		b <<= 1;
		scl_high(i2c);
		halfDelay();

		if(pin_is_high(i2c->sda)){
			b |= 1;
		}
		scl_low(i2c);
		halfDelay();
	}

	// Put the ACK
	if(isLastByte){
		sda_high(i2c);
	}else{
		sda_low(i2c);
	}
	scl_high(i2c);
	halfDelay(i2c);
	scl_low(i2c);
	sda_high(i2c);

	return b;						// return received byte
}
Esempio n. 4
0
//------------------------------------------------------------------------
static unsigned int i2c_write_byte ( unsigned int b )
{
    unsigned int ra;
    for(ra=0x80;ra;ra>>=1)
    {
        i2c_delay();
        if(ra&b) sda_high();
        else     sda_low();
        i2c_delay();
        scl_high();
        i2c_delay();
        scl_low();
        i2c_delay();
        sda_low();
        i2c_delay();
    }
    i2c_delay();
    sda_input();
    i2c_delay();
    scl_high();
    i2c_delay();
    ra=sda_read();
    i2c_delay();
    scl_low();
    i2c_delay();
    sda_output();
    i2c_delay();
    return(ra);
}
Esempio n. 5
0
static void init(I2C_ABSTRACT_BUS* bus){
	const I2C_SOFTWARE_BUS* i2c = (I2C_SOFTWARE_BUS*)bus;

	// Make both pins high
	sda_high(i2c);
	scl_high(i2c);
}
Esempio n. 6
0
// Send the start and address
// return TRUE if acknowledged
static boolean start(const I2C_ABSTRACT_BUS* bus, uint8_t addr, boolean writeMode){
	boolean rtn = FALSE;

	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)bus;
	if(i2c){
		sda_high(i2c);
		halfDelay();
		scl_high(i2c);
		halfDelay();

		sda_low(i2c);
		halfDelay();
		scl_low(i2c);
		halfDelay();

		// Send the device addr and direction
//		uint8_t addr = device->addr & 0xfe;
		if(writeMode==FALSE){
			addr |= 1;
		}else{
			addr &= 0xfe;
		}
		rtn = putByte(bus, addr);
	}
	return rtn;
}
Esempio n. 7
0
// Return true if the slave acknowledges
static boolean getAck(const I2C_SOFTWARE_BUS* i2c){
	sda_high(i2c);	// allow slave to drive sda
	scl_high(i2c);
	halfDelay();
	boolean rtn = pin_is_low(i2c->sda);
	scl_low(i2c);

	return rtn;
}
Esempio n. 8
0
// Send the stop
static void stop(const I2C_ABSTRACT_BUS* bus){
	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)bus;
	sda_low(i2c);
	halfDelay();
	scl_high(i2c);
	halfDelay();
	sda_high(i2c);
	halfDelay();
}
Esempio n. 9
0
//------------------------------------------------------------------------
static void i2c_stop ( void )
{
    i2c_delay();
    scl_high();
    i2c_delay();
    sda_high();
    i2c_delay();
    i2c_delay();
}
Esempio n. 10
0
File: sht.c Progetto: promovicz/rtos
void sht_start(void)
{
    sda_output();

    sda_set(0);
    scl_low();
    scl_high();
    sda_set(1);
    scl_low();
}
Esempio n. 11
0
// Put a byte across the wire
// Return true if the slave acknowledges
static boolean putByte(const I2C_ABSTRACT_BUS* bus, uint8_t b){
	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)bus;
	int8_t i;

	for(i=7; i>=0; i--){
		if( b & 0x80 ){
			sda_high(i2c);
		}else{
			sda_low(i2c);
		}
		scl_high(i2c);
		b <<= 1;
		scl_low(i2c);
	}
	return getAck(i2c);						// return ACK value
}
Esempio n. 12
0
int main(void) {

 int test;
 unsigned char byte;
// PCF_ADRESS = 0;	// Adresse des PCF'S 
 
 printf("*** i²c-LCD Test (c) Ingo Gerlach 10/2000 *** \n");
 COM  = 0; 			// Vorbelegung Ser - Port, 0 Automatisch suchen
 set_port_delay(15);		// Portdelay 0-255 
 test = init_iic(COM);		// Init ii2c 
 printf("Suche i2c-Interface...");
 if (test) 
 {
  printf(" gefunden an Port 0x%03xh! \n",test);
 } else {
    printf("Interface nicht gefunden.\n");
    exit (0);
  }
/*
 set_strobe(1);			// Für den Seriellen Port nur dummy
 io_disable(0);
*/
 sda_high();
 scl_high();
 printf("read_sda %d \n",read_sda());
 printf("read_scl %d \n",read_scl());
 iic_start();
 byte =getchar();
 iic_stop();
 sda_low();
 scl_low();
 printf("read_sda %d \n",read_sda());
printf("read_scl %d \n",read_scl());    
lcd_backlight(0); 
byte = getchar();
 printf("deinit %d\n",deinit_iic()); 
 return 0;
}
Esempio n. 13
0
// Send the start and address
// return TRUE if acknowledged
static boolean start(const I2C_DEVICE* device, boolean writeMode){
	boolean rtn = FALSE;

	const I2C_SOFTWARE_BUS* i2c = (const I2C_SOFTWARE_BUS*)(device->bus);
	if(i2c){
		sda_high(i2c);
		halfDelay();
		scl_high(i2c);
		halfDelay();

		sda_low(i2c);
		halfDelay();
		scl_low(i2c);
		halfDelay();

		// Send the device addr and direction
		uint8_t addr = device->addr & 0xfe;
		if(writeMode==FALSE){
			addr |= 1;
		}
		rtn = putByte(device->bus, addr);
	}
	return rtn;
}