Пример #1
0
uint8_t main()
{
	//initialization
	uint16_t lm73_temp;
	init_twi();
	uart_init();

	//set LM73 mode for reading temperature by loading pointer register
	//this is done outside of the normal interrupt mode of operation 
	lm73_wr_buf[0] = LM73_PTR_TEMP; //load lm73_wr_buf[0] 
					//with temperature pointer address
	twi_start_wr(LM73_WRITE, lm73_wr_buf, 2); //start the TWI write process
	sei();             //enable interrupts to allow start_wr to finish

	while(1)
	{
		//read temperature data from LM73  (2 Bytes)
		twi_start_rd(LM73_READ, lm73_rd_buf, 2);
		_delay_ms(2);    //wait for it to finish

		//now assemble the two bytes read back into one 16-bit value
		lm73_temp = lm73_rd_buf[0]<<8;  //save high temperature byte 
		lm73_temp |= lm73_rd_buf[1];//"OR" in the low temp byte to lm73_temp 
		lm73_temp = lm73_temp >>7; //parse out decimal place
		itoa(lm73_temp, temp_val, 10); //convert to string in array 
		uart_puts(temp_val);
	}
}
Пример #2
0
void read_LSM6DS3(uint8_t address, uint8_t *rd_buf){

    uint8_t addr_buf[1];

    // Save address to address buffer
    addr_buf[0] = address;

    // Write register address of where to read data from
    twi_start_wr(LSM6DS3_WRITE, addr_buf, 1);

    // Recieve data from register address and store in rd_buf
    twi_start_rd(LSM6DS3_READ, rd_buf, 1);

    // Wait until data is recieved
    while(twi_busy());
}
Пример #3
0
/*****************************************************************************************
 * Function:		read_lm73
 * Description:		Function reads temperature data from sensor over twi and converts
 * 			 farenhiet or celsius basec on 3rd argument to lm73_temp_convert
 * Arguments:		None
 * Return:		None
 ****************************************************************************************/
void read_lm73()
{
	twi_start_rd(LM73_ADDRESS, lm73_rd_buf, 2);

	/* Copy high byte in */
	lm73_temp = lm73_rd_buf[0];

	/* Shift high byte to high byte location */
	lm73_temp <<= 8;

	/* Bring in the low byte */
	lm73_temp |= lm73_rd_buf[1];

	/* Convert int to string */
	lm73_temp_convert(read_temp_string, lm73_temp, C);

	/* Copy the digits to the display string */
	lcd_temp_string[3] = read_temp_string[0];
	lcd_temp_string[4] = read_temp_string[1];
}
Пример #4
0
int main ()
{     
   uint16_t lm73_temp;  //a place to assemble the temperature from the lm73

   spi_init();   //initalize SPI 
   lcd_init();   //initalize LCD (lcd_functions.h)
   init_twi();   //initalize TWI (twi_master.h)  

   lm73_resolution_config();

   //set LM73 mode for reading temperature by loading pointer register
   //this is done outside of the normal interrupt mode of operation 
   //load lm73_wr_buf[0] with temperature pointer address
   lm73_wr_buf[0] = LM73_PTR_TEMP; 
   //start the TWI write process (twi_start_wr())
   twi_start_wr(LM73_ADDRESS, lm73_wr_buf, 1); 

   //enable interrupts to allow start_wr to finish
   sei();             

   clear_display();   //clean up the display

   while(1){          //main while loop
      _delay_ms(100);  //tenth second wait
      clear_display(); //wipe the display

      //read temperature data from LM73 (2 bytes)  (twi_start_rd())
      twi_start_rd(LM73_ADDRESS, lm73_rd_buf, 2); 
      _delay_ms(2);    //wait for it to finish
      //now assemble the two bytes read back into one 16-bit value
      lm73_temp = lm73_rd_buf[0]; //save high temperature byte into lm73_temp
      lm73_temp <<= 8; //shift it into upper byte 
      lm73_temp |= lm73_rd_buf[1]; //"OR" in the low temp byte to lm73_temp 
      itoa(lm73_temp, lcd_string_array, 2); //convert to string in array with itoa() from avr-libc                           
      string2lcd(lcd_string_array); //send the string to LCD (lcd_functions)
   } //while
} //main