Beispiel #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);
	}
}
Beispiel #2
0
/*****************************************************************************************
 * Function:		lm73_init
 * Description:		Initializes local temp sensor over twi
 * Arguments:		None
 * Return:		None
 ****************************************************************************************/
void lm73_init()
{
	/* Sends read address to the slave */
	lm73_wr_buf[0] = LM73_PTR_TEMP;
	twi_start_wr(LM73_ADDRESS, lm73_wr_buf, 1);
	_delay_ms(2);
}
Beispiel #3
0
//******************************************************************************
void lm73_set_ptr_to_read(void){
   //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);

   return;
}
Beispiel #4
0
//******************************************************************************
void lm73_set_max_resolution(void){
   //FIXME
   lm73_wr_buf[0] = LM73_PTR_CTRL_STATUS;
   //lm73_wr_buf[0] = LM73_PTR_TEMP;   
   lm73_wr_buf[1] = (1<<RES1 | 1<<RES0);
   twi_start_wr(LM73_ADDRESS, lm73_wr_buf, 2);
   //twi_start_wr(LM73_ADDRESS, lm73_wr_buf[1], 1);

   return ;
}
Beispiel #5
0
void write_LSM6DS3(uint8_t address, uint8_t value){

    uint8_t wr_buf[2];

    // Save address to address buffer
    wr_buf[0] = address;
    wr_buf[1] = value;

    // Write value to register address
    twi_start_wr(LSM6DS3_WRITE, wr_buf, 2);
    
    // Wait until data is sent
    while(twi_busy());

}
Beispiel #6
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());
}
Beispiel #7
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
Beispiel #8
0
/* Func: lm73_resolution_config(void)
 * Desc: The function will set the precision resolution of the
 *   digital termometer to 14-bit precision (13 bits w/ a sign bit)
 */
void lm73_resolution_config(void){
   //load lm73_wr_buf[0] with temperature pointer address
   lm73_wr_buf[0] = (1<<RES1 | 1<<RES0); 
   //start the TWI write process 
   twi_start_wr(LM73_PTR_CTRL_STATUS, lm73_wr_buf, 1); 
}