Exemplo n.º 1
0
uint16_t max31855_read()
{
	MAX31855_t max31855;
	uint8_t data[4];
	
	//Switch CS to low to initiate data transfer
	MAX31855_CS_PORT &= ~(1<<MAX_31855_CS_PIN_1);
	
	//Get bits D31 to D24
	spi_master_transmit(0xFF);
	data[0] = SPDR;
	
	//Get bits D23 to D16
	spi_master_transmit(0xFF);
	data[1] = SPDR;
	
	//Get bits D15 to D8
	spi_master_transmit(0xFF);
	data[2] = SPDR;
	
	//Get bits D7 to D0
	spi_master_transmit(0xFF);
	data[3] = SPDR;
	
	//Switch CS back to high to end data transfer
	MAX31855_CS_PORT |= (1<<MAX_31855_CS_PIN_1);
	
	#ifdef DEBUG_BUILD
	char buffer[8];
	uart0_print("Raw Value: ");
	itoa(data[0], buffer, 16); uart0_print(buffer); uart0_print(" ");
	itoa(data[1], buffer, 16); uart0_print(buffer); uart0_print(" ");
	itoa(data[2], buffer, 16); uart0_print(buffer); uart0_print(" ");
	itoa(data[3], buffer, 16); uart0_print(buffer); uart0_print(" ");
	uart0_print(", ");
	#endif
	
	//The two most significant bytes hold the thermocouple temp
	max31855.thermocoupleTemp = ((data[0]<<8)|(data[1]));
	
	//Check if the value is negative
	if((max31855.thermocoupleTemp & 0x8000) == 0x8000)
		max31855.signBit = 1;

	//Check if the fault bit(Bit 16) is 1
	if((max31855.thermocoupleTemp & 0x0001) == 0x0001)
	{
		max31855.faultBit = 1;
		#ifdef DEBUG_BUILD
		uart0_print("Fault Detected, ");
		#endif
	}
	
	//Shift out bits D16 and D17	
	max31855.thermocoupleTemp = (max31855.thermocoupleTemp >> 2);
	
	return max31855.thermocoupleTemp;
}
Exemplo n.º 2
0
uint8_t knock_module_initialize(void)
{
 uint8_t i, response;
 uint8_t init_data[2] = {KSP_SET_PRESCALER | KSP_PRESCALER_VALUE | KSP_SO_TERMINAL_ACTIVE,
                         KSP_SET_CHANNEL | KSP_CHANNEL_0};
 uint8_t _t;

 _t=_SAVE_INTERRUPT();
 _DISABLE_INTERRUPT();

 //Setting HOLD mode for integrator and "Run" mode for chip at all.
 SET_KSP_TEST(1);
 SET_KSP_INTHOLD(KNOCK_INTMODE_HOLD);
 SET_KSP_CS(1);

 spi_master_init();
 ksp.ksp_interrupt_state = 0; //init state machine
 ksp.ksp_error = 0;

 //set prescaler first
 SET_KSP_CS(0);
 spi_master_transmit(init_data[0]);
 SET_KSP_CS(1);

 //Setting SO terminal active and perform initialization. For each parameter perform
 //checking for response and correcntess of received data.
 for(i = 0; i < 2; ++i)
 {
  SET_KSP_CS(0);
  spi_master_transmit(init_data[i]);
  SET_KSP_CS(1);
  response = SPDR;
  if (response!=init_data[i])
  {
   _RESTORE_INTERRUPT(_t);
   return 0; //error - chip doesn't respond!
  }
 }

 _RESTORE_INTERRUPT(_t);
 //Initialization completed successfully
 return 1;
}