예제 #1
0
uint8_t Init_Twi(int index)
{
  if(index > (sizeof(twi_instances)/sizeof(twi_instances[0])))
  {
    return 0;
  }
  if(twi_Init[index] == 1)
  {
    return 1; // allready initialized.
  }
  freertos_peripheral_options_t async_driver_options = {
      NULL,
      0,
      (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1),
      TWI_I2C_MASTER,
      (USE_TX_ACCESS_MUTEX | USE_RX_ACCESS_MUTEX | WAIT_TX_COMPLETE | WAIT_RX_COMPLETE),
  };

  /*Initialize twi bus.*/
  freertos_twi_if twi = freertos_twi_master_init( twi_instances[index],
      &async_driver_options );


  if ( twi == NULL )
  {
    return 0;
  }
  freeRTOS_twi[index] = twi;
  twi_set_speed( twi_instances[index], 400000, sysclk_get_cpu_hz() ); /*High speed TWI setting*/
  twi_Init[index] = 1;
  return 1;
}
예제 #2
0
static uint8_t twi_init(void){
	freertos_peripheral_options_t driver_options = {
		//Receiver Buffer
		NULL,
		//Size Receiver Buffer
		0,
		//Priority Interrupt
		(configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY),
		TWI_I2C_MASTER,
		( USE_TX_ACCESS_MUTEX | USE_RX_ACCESS_MUTEX | WAIT_TX_COMPLETE | WAIT_RX_COMPLETE)
	};
	
	freertos_twi = freertos_twi_master_init(TWI0, &driver_options);
	
	configASSERT(freertos_twi);
	uint8_t twi_flag = twi_set_speed(TWI0, TWI_SPEED, sysclk_get_cpu_hz());
	return twi_flag;
}