Esempio n. 1
0
void setUp() {
    init_fake_port();
	twi_tests_setUp();
	twea_flag = 0;
	BOOL res = twi_init(testPin1, testPin2);
    TEST_ASSERT_TRUE_MESSAGE(res, "failed to initialize twi master.");
}
Esempio n. 2
0
int main( void )
 
{
	
	twi_init();		// Init TWI interface

	// Init HT16K22. Page 32 datasheet
	twi_start();
	twi_tx(0xE0);	// Display I2C addres + R/W bit
	twi_tx(0x21);	// Internal osc on (page 10 HT16K33)
	twi_stop();

	twi_start();
	twi_tx(0xE0);	// Display I2C address + R/W bit
	twi_tx(0xA0);	// HT16K33 pins all output
	twi_stop();

	twi_start();
	twi_tx(0xE0);	// Display I2C address + R/W bit
	twi_tx(0xE3);	// Display Dimming 4/16 duty cycle
	twi_stop();

	twi_start();
	twi_tx(0xE0);	// Display I2C address + R/W bit
	twi_tx(0x81);	// Display OFF - Blink On
	twi_stop();

	twi_clear();

		play_fill_animation();
		clear_rows();
	
	return 1;
	}
Esempio n. 3
0
int main(void)
{
	DDRA=0xFF;
	PORTA=0x00;

	uint8_t time[3];
	uint8_t Flag,Flag1;
	usartInit();
	printf("*--------------------------------------------------- *\r\n");
	printf("*-------------------AT24CXX experiment-------------- *\r\n");
	printf("*--------------------------------------------------- *\r\n");


	twi_init();	
	PCF8563_init();	
	PCF8563_setTime(0,0,0); 
	
	while(1)
	{	
		while(1)
		{
			PCF8563_getTime(time);

			if(Flag1 != Flag)
			{
				PORTA = time[0];
				printf("Real time clock  %d:%d:%d \r \n",time[2],time[1],time[0]);
				Flag1=Flag;
			}  	
			Flag = time[0];

		}
	}
}
Esempio n. 4
0
int
main (void)
// This is just a place holder application that will be replaced by
// bootloader programming.  When built with BOOTSTRAPPER defined the
// application will allow the bootloader itself to be programmed.
{

#ifdef BOOTSTRAPPER
    // Initialize the bootloader exit and active flags.
    bootloader_exit = 0;
    bootloader_active = 0;

    // Initialize programming module.
    prog_init();

    // Initialize TWI module.
    twi_init();
#endif

    // Loop forever.
    for (;;)
    {
#ifdef BOOTSTRAPPER
        // Check for TWI conditions that require handling.
        twi_check_conditions();
#endif
    }

#ifdef BOOTSTRAPPER
    // Restore TWI interface to powerup defaults.
    twi_deinit();
#endif

    return 0;
}
Esempio n. 5
0
File: demo.c Progetto: kerichsen/asf
int main(void)
{
  init_sys_clocks();

  init_dbg_rs232(FPBA_HZ);

  print_dbg("AVR UC3 DSP DEMO\r\n");

  irq_initialize_vectors();

  // GUI, Controller and DSP process init
  gui_init(FCPU_HZ, FHSB_HZ, FPBA_HZ, FPBB_HZ);
  gui_text_print(GUI_COMMENT_ID, TEXT_IDLE);
  gui_text_print(GUI_FILTER_ID, filter_active_get_description());
  controller_init(FCPU_HZ, FHSB_HZ, FPBA_HZ, FPBB_HZ);
  twi_init();
  dsp_process_init(FCPU_HZ, FHSB_HZ, FPBA_HZ, FPBB_HZ);

  cpu_irq_enable();

  // Main loop
  while (1)
  {
    gui_task();
    controller_task();
    dsp_process_task();
    state_machine_task();
  }
}
Esempio n. 6
0
/* returns
 * - success: 0
 */
uint8_t teensy_init(void) {
	CPU_PRESCALE(CPU_16MHz);  // speed should match F_CPU in makefile

	// onboard LED
	DDRD  &= ~(1<<6);  // set D(6) as input
	PORTD &= ~(1<<6);  // set D(6) internal pull-up disabled

	// keyboard LEDs (see "PWM on ports OC1(A|B|C)" in "teensy-2-0.md")
	_led_all_off();  // (just to put the pins in a known state)
	TCCR1A  = 0b10101001;  // set and configure fast PWM
	TCCR1B  = 0b00001001;  // set and configure fast PWM

	// I2C (TWI)
	twi_init();  // on pins D(1,0)

	// unused pins
	teensypin_write_all_unused(DDR, CLEAR); // set as input
	teensypin_write_all_unused(PORT, SET);  // set internal pull-up enabled

	// rows
	teensypin_write_all_row(DDR, CLEAR); // set as input
	teensypin_write_all_row(PORT, SET);  // set internal pull-up enabled

	// columns
	teensypin_write_all_column(DDR, CLEAR);   // set as input (hi-Z)
	teensypin_write_all_column(PORT, CLEAR);  // set internal pull-up
	                                          //   disabled

	return 0;  // success
}
void GadgetShield::Setup(void)
{
  // Configure infrared emitter and detector
  pinMode(IRIN_PIN, INPUT);     // There is already an external pullup in the detector itself but it
  digitalWrite(IRIN_PIN, HIGH); // doesn't hurt to add our own pullup as the detector's is weak.
  pinMode(IROUT_PIN, OUTPUT);
  digitalWrite(IROUT_PIN, LOW);

  // Configure general-purpose LED's
  pinMode(LED1_PIN, OUTPUT); pinMode(LED2_PIN, OUTPUT); pinMode(LED3_PIN, OUTPUT); pinMode(LED4_PIN, OUTPUT);
  digitalWrite(LED1_PIN, LOW); digitalWrite(LED2_PIN, LOW); digitalWrite(LED3_PIN, LOW); digitalWrite(LED4_PIN, LOW);

  // Configure RGB LED
  pinMode(RED_PIN, OUTPUT); pinMode(GREEN_PIN, OUTPUT); pinMode(BLUE_PIN, OUTPUT);
  RGB(0,0,0);

  // Configure pushbuttons
  pinMode(PB1_PIN, INPUT); // There are already external pullups so no internal pullup is needed
  pinMode(PB2_PIN, INPUT);

  // Configure speaker
  pinMode(SPEAKER_PIN, OUTPUT);
  digitalWrite(SPEAKER_PIN, LOW);
  Speaker(1000); // Just to initialize timer infrastructure for speaker and Blue RGB LED pin
  Speaker(0);

  // Configure TWI interface to accelerometer and restore to default settings
  twi_init();

  // Initialize accelerometer
  accel_init();

  // Assume microphone baseline is 2.5V. Establish experimentally by calling MicrophoneSetBaseline().
  m_mic_baseline = 127;
}
Esempio n. 8
0
void hh10d_init(void *cfg) {
    // Read calibrate paremeter with TWI
    int rc;
    char buf[6];
    twi_init();
    rc = ee24xx_read_bytes(10,4,buf);
    if (rc != 4) {
        sens = 0;
        offset = 0;
        return;
    }
#ifdef DEBUG
    uart_hexdump(buf,4);
    uart_putc ('\r');
    uart_putc ('\n');
#endif
    sens = buf[0] * 256 + buf[1];
    offset = buf[2] * 256 + buf[3];
#ifdef DEBUG
    itoa(sens,buf,10);
    uart_putstr(buf);
    uart_putstr_P(PSTR("\r\n"));
    itoa(offset,buf,10);
    uart_putstr(buf);
    uart_putstr_P(PSTR("\r\n"));
#endif

    // rising edge
    EICRA |= (1 << ISC10) | (1 << ISC11);
    // enable INT1
    EIMSK |= (1 << INT1);
}
int main(void)
{
	// Enable peripherals
	system_init();
	pins_init();
	us1_init();
	us0_init();
	twi_init();

	// Initialize state machines
	qcfp_init();
	eq_init();

	// Once everything is initialized, enable interrupts globally
	interrupts_enable();

	// Enable Expansion module 3 and 4 (sensors plugged into these temporarily)
	AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA20;
	AT91C_BASE_PIOA->PIO_CODR = AT91C_PIO_PA23;

	sensors_init();

	eq_post_timer(gpio_led_dance, 250, eq_timer_periodic);

	while(1)
	{
		eq_dispatch();
		eq_dispatch_timers();
	}
	return 0;
}
Esempio n. 10
0
int main(void)
{
    char str[30];
    status_init();
    adc_init();
    
    status_set(false);
    
    uart_init(1);
    twi_init(0xC);
    twi_enable_interrupt();
    twi_register_get(get);
    
    measurement = 0;
    
    sei();
    
    while (1) {
        
        // VRef is 2.56V
        // at T = 0, VOut = 0V. VOut scales at 10mV / ºC
        // T = adc * (2.56 / 1024) * 100
        // T = adc * 256 / 1024
        // T = adc / 4
        uint16_t read = adc_read();
        measurement = read / 4;
        sprintf(str, "%dºC (raw = %d)", measurement, read);
        
        uart_send(str);
        _delay_ms(500);
    }
    
}
Esempio n. 11
0
/**
 * @brief TWI initialization.
 */
static ret_code_t twi_init (void)
{
    ret_code_t err_code;

    const nrf_drv_twi_config_t twi_mcp4725_config = {
       .scl                = ARDUINO_SCL_PIN,
       .sda                = ARDUINO_SDA_PIN,
       .frequency          = NRF_TWI_FREQ_100K,
       .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
       .clear_bus_init     = false
    };

    err_code = nrf_drv_twi_init(&m_twi, &twi_mcp4725_config, twi_handler, NULL);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    nrf_drv_twi_enable(&m_twi);
    return NRF_SUCCESS;
}

ret_code_t mcp4725_setup(void)
{
    ret_code_t err_code = twi_init();
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    return NRF_SUCCESS;
}
Esempio n. 12
0
void test_initialization() {
	TEST_ASSERT_EQUAL_HEX(_BV(TWEN) | _BV(TWIE), TWCR);
	TEST_ASSERT_EQUAL_HEX(0x00, TWDR);
    BOOL res = twi_init(testPin1, testPin2);
    TEST_ASSERT_FALSE_MESSAGE(res, "Second initialization of twi master should not be possible");
    TEST_ASSERT_EQUAL(PinTwiIO, pinOccupation(testPin1));
    TEST_ASSERT_EQUAL(PinTwiIO, pinOccupation(testPin2));
}
Esempio n. 13
0
File: test1.c Progetto: Devj92/test1
// initialise the devices 
void init_devices()
{
 cli();              // disable all interrupts 
 lcd_port_config();  // configure the LCD port 
 twi_init();         // configur the I2cC, i.e TWI module 
 sei();              // re-enable interrupts
 //all peripherals are now initialized
}
Esempio n. 14
0
void twi_begin() {
	rxBufferIndex = 0;
	rxBufferLength = 0;

	txBufferIndex = 0;
	txBufferLength = 0;

	twi_init();
}
Esempio n. 15
0
void TwoWire::begin(bool use_internal_pull_up)
{
  rxBufferIndex = 0;
  rxBufferLength = 0;

  txBufferIndex = 0;
  txBufferLength = 0;

  twi_init(use_internal_pull_up);
}
Esempio n. 16
0
uint8_t twi_tout(uint8_t ini)
{
  if (ini) twi_toutc=0; else twi_toutc++;	
  if (twi_toutc>=100000UL) {
    twi_toutc=0;
    twi_init();
    return 1;
  }
  return 0;  
}
Esempio n. 17
0
void TwoWire::begin(uint32_t speed)
{
  rxBufferIndex = 0;
  rxBufferLength = 0;

  txBufferIndex = 0;
  txBufferLength = 0;

  twi_init(speed);
}
Esempio n. 18
0
void TwoWire::begin(void)
{
  rxBufferIndex = 0;
  rxBufferLength = 0;

  txBufferIndex = 0;
  txBufferLength = 0;

  twi_init((p32_i2c *)_TWI_BASE, _TWI_BUS_IRQ, _TWI_SLV_IRQ, _TWI_MST_IRQ, _TWI_VECTOR);
}
Esempio n. 19
0
void twi_init_master(void)
{
  rxBufferIndex = 0;
  rxBufferLength = 0;

  txBufferIndex = 0;
  txBufferLength = 0;

  twi_init();
}
Esempio n. 20
0
void TwoWire::begin(void)
{
  rxBufferIndex = 0;
  rxBufferLength = 0;

  txBufferIndex = 0;
  txBufferLength = 0;

  twi_init();
}
Esempio n. 21
0
void config_IMU(void){
	if (twi_init() == TWI_SUCCESS){
		adxl_init();
		itg_init();
		} else {
		while(1){
			gpio_toggle_pin(LED2_GPIO);
			mdelay(5000);	//Delay 500.0 ms
		}
	}
}
Esempio n. 22
0
void twi_ctor(void)
{
	SERIALSTR("twi_ctor()\r\n");

	QActive_ctor((QActive*)(&twi), (QStateHandler)&twiInitial);
	twi_init();
	twi.requests[0] = 0;
	twi.requests[1] = 0;
	twi.requestIndex = 0;
	twi.ready = 0;
}
Esempio n. 23
0
uint8_t twi_tout(uint8_t ini)
{
	if (ini) twi_toutc=0; else twi_toutc++;
	if (twi_toutc>=wait_count) {
        twi_toutc=0;
        uint8_t TWBR_bak=TWBR;
        twi_init(use_internal_pull_up);
        TWBR=TWBR_bak;
        return 1;
	}
  return 0;
}
Esempio n. 24
0
int main(void)
{
	char packet[1500];
	struct cfg_s cfg;
	
	/*wait 500 for ethernet*/
	_delay_ms(500);
	
	enc_init();
	twi_init();
	spi_init();
	ip_init();
	pwm_init();
	sei();
	
	/*
	 * EEPROM:
	 * Mac Address:6
	 * IP:4
	 * Subnet Mask:4
	 * Port:2
	 * ID:4
	 */
	eeprom_read_block(&eecfg,  &cfg, sizeof(struct cfg_s));
	
	ip_setipmac((char*)cfg.ip, (char*)cfg.subnet, (char*)cfg.mac);
	
	while(1) {
		/*
		 * Provide encoder deltas
		 * Provide Integrated/Corrected Gyro
		 * Accelerometer?
		 * Pipe PWMS
		 * Pipe Spike
		 * IP? - TCP/UDP
		 * 
		 * Do reliability on cpu side.
		 * Send immediate acks only.
		 * 
		 * Timeout of 250 ms?
		 */
		/* TODO:
		 *  ANALOG:
		 *   GYRO
		 *   TEMP
		 *  ACCELEROMETER
		 *  CONTROL STATION
		 *  PID?
		 */
		/*LOOP*/
	}
}
Esempio n. 25
0
void TwoWire::begin(uint32_t speed, uint8_t address)
{
  rxBufferIndex = 0;
  rxBufferLength = 0;

  txBufferIndex = 0;
  txBufferLength = 0;

  twi_init(speed);
  twi_setAddress(address);
  twi_attachSlaveTxEvent(onRequestService);
  twi_attachSlaveRxEvent(onReceiveService);
}
Esempio n. 26
0
void TwoWireMaster::begin(void)
{
  rxBufferIndex = 0;
  rxBufferLength = 0;

  txBufferIndex = 0;
  txBufferLength = 0;
#if ORG_FILE
  twi_init();
#else ORG_FILE
  twiMstrBegin(I2C_100KHZ, I2C_INTERNAL_PULLUPS);
#endif  // ORG_FILE
}
Esempio n. 27
0
void TwoWire::begin(void)
{
  // init buffer for reads
  rxBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
  rxBufferIndex = 0;
  rxBufferLength = 0;

  // init buffer for writes
  txBuffer = (uint8_t*) calloc(BUFFER_LENGTH, sizeof(uint8_t));
  txBufferIndex = 0;
  txBufferLength = 0;

  twi_init();
}
Esempio n. 28
0
imu::imu(void)
{       twi_init(); // Initialize all peripherals.
        accl_init();
	    mag_init();
	    gyro_init();
		
	    gyro_roll_angle = 0; // Initialize internal variables to zero.
        gyro_pitch_angle = 0;
	    roll_angle = 0;
        pitch_angle = 0;
        yaw_angle = 0;
        
        //gyro_x_position(void)
}
Esempio n. 29
0
int main (void)
{
    m_clockdivide(0);
    twi_init(I2C_ADDR);
    while(1)
    {
        
        if (receive_done)
        {
            process_command();
            receive_done = false;
            TWI_ACK();
        }
    }
}
void act8865_workaround(void)
{
	if (!twi_init_done)
		twi_init();

	/* Set ACT8865 REG output voltage */
	at91_board_act8865_set_reg_voltage();

	/* Disable ACT8865 I2C interface, if failed, don't go on */
	if (act8865_workaround_disable_i2c()) {
		dbg_info("ACT8865: Failed to disable I2C interface\n");
		while (1)
			;
	}
}