示例#1
0
void main()
{
#define ADDR    0x00
    u8 i = 0;
    u8 Data;
    uart_init(UART1, 19600);                        //初始化串口

    I2C_init(I2C0);                                 //初始化I2C0

    printf("AT24C02 I2C 实验\n\n");
    printf("\t\t——野火kinetis开发板\n\n");

    while(1)
    {
        for(i = 0; i < 255; i++)
        {
            I2C_WriteAddr(I2C0, AT24C02_I2C_ADDRESS, ADDR, i);          //I2C向AT24C02_I2C_ADDRESS芯片写入数据 i 到地址为ADDR的寄存器
            Data    =   I2C_ReadAddr(I2C0, AT24C02_I2C_ADDRESS, ADDR);  //I2C向AT24C02_I2C_ADDRESS芯片读取寄存器地址为ADDR的数据

            printf("接收到的数据为:%d\n\n", Data);                     //发送到串口显示出来

            time_delay_ms(1000);                                        //延时1s
        }
    }
#undef  ADDR
}
示例#2
0
void bspI2cInit(void)
{
    Semaphore_Params semParamsMutex;

    // Create protection semaphore
    Semaphore_Params_init(&semParamsMutex);
    semParamsMutex.mode = Semaphore_Mode_BINARY;
    Semaphore_construct(&mutex, 1, &semParamsMutex);

    // Reset the I2C controller
    HWREG(PRCM_BASE + PRCM_O_RESETI2C) = PRCM_RESETI2C_I2C;

    I2C_init();
    I2C_Params_init(&I2CParams);
    I2CParams.bitRate = I2C_400kHz;
    I2Chandle = I2C_open(Board_I2C, &I2CParams);

    // Initialize local variables
    slaveAddr = 0xFF;
    interface = BSP_I2C_INTERFACE_0;
#ifdef POWER_SAVING
    checkI2cConstraint = false;
#endif

    /*
    if (I2Chandle == NULL) {
      while(1) {
        // wait here for ever
      }
    }
    */
}
示例#3
0
void main(int argc, char** argv, int entrypoint)
{
    (void) argc;
    (void) argv;

    PXI_Reset();
    I2C_init();

    // Wait for ARM11
    PXI_WaitRemote(PXI_READY);

    PXI_DoCMD(PXI_SCREENINIT, NULL, 0);
    I2C_writeReg(I2C_DEV_MCU, 0x22, 0x2A);

    #ifdef SCRIPT_RUNNER
    // Run the script runner
    if (ScriptRunner(entrypoint) == GODMODE_EXIT_REBOOT)
    #else
    // Run the main program
    if (GodMode(entrypoint) == GODMODE_EXIT_REBOOT)
    #endif
        Reboot();

    PowerOff();
}
示例#4
0
//==========================================
//初始化HMC5883
//==========================================
void HMC5883_Init(void)
{
	I2C_init();
//	I2C_Write_Reg(0x00,0x70);
//	I2C_Write_Reg(0x01,0x00);
	I2C_Write_Reg(0x02,0x00);
}
示例#5
0
void rt_init_thread_entry(void* parameter)
{
    /* init board */
    //    rt_hw_led_init();
    I2C_init();
    pwm_init();
    Init_MPU6050();
    HMC5883L_Initialize();

    //    at_application_init();

#ifdef RT_USING_COMPONENTS_INIT
    /* initialization RT-Thread Components */
    rt_components_init();
#endif

#ifdef  RT_USING_FINSH
    finsh_set_device(RT_CONSOLE_DEVICE_NAME);
#endif  /* RT_USING_FINSH */

    /* Filesystem Initialization */
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
    /* mount sd card fat partition 1 as root directory */
    if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
    {
        rt_kprintf("File System initialized!\n");
    }
    else
        rt_kprintf("File System initialzation failed!\n");
#endif  /* RT_USING_DFS */

    at_application_init();
    BT_application_init();
    imu_application_init();
}
示例#6
0
/*******************************************************************************
 * @fn          bspI2cInit
 *
 * @brief       Initialize the RTOS I2C driver (must be called only once)
 *
 * @param       none
 *
 * @return      none
 */
void bspI2cInit(void)
{
  Semaphore_Params semParamsMutex;

  // Create protection semaphore
  Semaphore_Params_init(&semParamsMutex);
  semParamsMutex.mode = Semaphore_Mode_BINARY;
  Semaphore_construct(&mutex, 1, &semParamsMutex);

  // Reset the I2C controller
  HapiResetPeripheral(PRCM_PERIPH_I2C0);

  I2C_init();
  I2C_Params_init(&i2cParams);
  i2cParams.bitRate = I2C_400kHz;
  i2cHandle = I2C_open(Board_I2C, &i2cParams);

  // Initialize local variables
  slaveAddr = 0xFF;
  interface = BSP_I2C_INTERFACE_0;

  if (i2cHandle == NULL)
  {
    Task_exit();
  }
}
示例#7
0
void lcdi2c_init(u8 numcol, u8 numline, u8 i2c_address)
{
	numcolmax  = numcol - 1;
	numlinemax = numline - 1;
	//PCF8574_address = 0b01001110 | i2c_address;
	PCF8574_address = i2c_address;
	PCF8574_data.val = 0;

	I2C_init(I2C_MASTER_MODE, I2C_100KHZ);

	//Delayms(15);								// Wait more than 15 ms after VDD rises to 4.5V
	lcdi2c_send4(0x30, LCD_CMD);			// 0x30 - Mode 8 bits
	//Delayms(5);									// Wait for more than 4.1 ms
	lcdi2c_send4(0x30, LCD_CMD);			// 0x30 - Mode 8 bits
	//Delayus(100);								// Wait more than 100 μs
	lcdi2c_send4(0x30, LCD_CMD);			// 0x30 - Mode 8 bits
	//Delayus(100);								// Wait more than 100 μs
	lcdi2c_send4(0x20, LCD_CMD);			// 0x20 - Mode 4 bits
	lcdi2c_send8(LCD_SYSTEM_SET_4BITS, LCD_CMD); 	// 0x28 - Mode 4 bits - 2 Lignes - 5x8
	//Delayus(4);				// Wait more than 40 ns
	lcdi2c_send8(LCD_DISPLAY_ON, LCD_CMD);		// 0x0C - Display ON + Cursor OFF + Blinking OFF
	//Delayus(4);				// Wait more than 40 ns
	lcdi2c_send8(LCD_DISPLAY_CLEAR, LCD_CMD);    	// 0x01 - Efface l'affichage + init. DDRAM
	Delayms(2);					// le temps d'execution de Display Clear > 1.64ms
	lcdi2c_send8(LCD_ENTRY_MODE_SET, LCD_CMD);   	// 0x06 - Increment + Display not shifted (Déplacement automatique du curseur)
	//Delayus(4);				// Wait more than 40 ns
	//lcdi2c_newpattern();				// Implante les nouveaux caracteres
}
示例#8
0
文件: Board_init.c 项目: energia/emt
/*
 *  ======== Board_openI2C ========
 *  Initialize the I2C driver.
 *  Initialize the I2C port's pins.
 *  Open the I2C port.
 */
I2C_Handle Board_openI2C(UInt i2cPortIndex, I2C_Params *i2cParams)
{
    
    /* Initialize the I2C driver */
    /* By design, I2C_init() is idempotent */
    I2C_init();
    
    /* initialize the pins associated with the respective I2C */
    switch (i2cPortIndex) {
        case 0:
            /*
             * Configure LaunchPad P1.9 as a I2C pin: LaunchPad Sensor Data (via I2C)
             *     device pin: 1 (I2C_SCL)
             *     Wiring id : 9
             */
            MAP_PinTypeI2C(PIN_01, PIN_MODE_1);

            /*
             * Configure LaunchPad P1.10 as a I2C pin: LaunchPad Sensor Data (via I2C)
             *     device pin: 2 (I2C_SDA)
             *     Wiring id : 10
             */
            MAP_PinTypeI2C(PIN_02, PIN_MODE_1);
            break;

        default:
            return (NULL);
    }

    /* open the I2C */
    return (I2C_open(i2cPortIndex, i2cParams));
}
示例#9
0
/*
 *  ======== EK_TM4C123GXL_initI2C ========
 */
void EK_TM4C123GXL_initI2C(void) {
	/* I2C1 Init */
	/* Enable the peripheral */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);

	/* Configure the appropriate pins to be I2C instead of GPIO. */
	GPIOPinConfigure(GPIO_PA6_I2C1SCL);
	GPIOPinConfigure(GPIO_PA7_I2C1SDA);
	GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
	GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);

	/* I2C3 Init */
	/* Enable the peripheral */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C3);

	/* Configure the appropriate pins to be I2C instead of GPIO. */
	GPIOPinConfigure(GPIO_PD0_I2C3SCL);
	GPIOPinConfigure(GPIO_PD1_I2C3SDA);
	GPIOPinTypeI2CSCL(GPIO_PORTD_BASE, GPIO_PIN_0);
	GPIOPinTypeI2C(GPIO_PORTD_BASE, GPIO_PIN_1);

	/*
	 * These GPIOs are connected to PD0 and PD1 and need to be brought into a
	 * GPIO input state so they don't interfere with I2C communications.
	 */
	GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
	GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_7);

	I2C_init();
}
int main( void )
{   
	sei();
 	Timer1_Init();
	I2C_init(0x52);	 
    USARTInit(9600);
//	SERVO_Init();
	
		
//	SERVO_UpdateServo(0,1500);
//	SERVO_UpdateServo(1,1800);
//	SERVO_UpdateServo(2,2600);
//	SERVO_UpdateServo(3,2800);
	

	//Timer1_print_time(Timer1_get_time());
	
	USARTWriteString("\r\nReset\r\n");
	SERVO_Run();

	
	
	while(1)
	{
		//handleI2C();
		//I2C_isdataready();
		
	}
	
	return 0;
}
示例#11
0
//*****************************************************************************
//
// 板级开发包初始化
//
//*****************************************************************************
void BSP_init(void)
{
    // Set the clocking to run directly from the crystal.
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_8MHZ);

    // Enable processor interrupts.
    IntMasterEnable();

    // Configure SysTick for a periodic interrupt.
    SysTickPeriodSet(SysCtlClockGet() / SYSTICKHZ);
    SysTickEnable();
    SysTickIntEnable();

    // Initialize the DEBUG UART.           (UART0)
    DEBUG_UART_init();

    // Initialize the IO Hardware.          (LED/SOL/I2C_HOTSWAP)
    IO_init();

    // Initialize the UART Hardware.        (ICMB/SOL)
    UART_init();

    // Initialize the SPI Hardware.         (SSIF)
    SPI_init();

    // Initialize the I2C Hardware.         (IPMB/PMB)
    I2C_init();

    // Initialize the Ethernet Hardware.    (LAN)
    ETH_init();
}
/*
 *  ======== SENSORTAG_CC2650_initI2C ========
 */
Void SENSORTAG_CC2650_initI2C(Void)
{
  /* Initialize drivers */
  I2C_init();
  
  /* Initialize IOs */
  I2CCC26XX_ioInit(I2C_config, BSP_I2C_INTERFACE_0);
}
示例#13
0
文件: slave.c 项目: kemaliu/kFishTank
int main()
{
    UINT32 val;
    char c, forceClearCfg = 0;
    /* enable watchdog */
    wdt_enable(WDTO_8S);
#ifdef INCLUDE_KTANK_UART
    /* init UART */
    init_uart(9600);
    printk("\n\n\n!!!!!!!!!!ktank start!!!!!!!!!!!!!!\n\n\n");
#endif
    /* init PWM, local time */
    pwm_init();
    /* enable i2c bus, rtc need it  */
    I2C_init();
    /* init timer */
    timer_init();
    val = timebase_get();
#ifdef INCLUDE_KTANK_UART
    do{
        if(uart_poll_c((UINT8*)&c) > 0 && c == 'c'){
            forceClearCfg++;
        }
    }while(time_diff_ms(val) < 2000);
#endif
    if(forceClearCfg > 10){
        DBG_PRINT("slave force clear cfg..\n");
        EEPROM_put(EEPROM_OFS_RFAVAIL, 0xff);
    }
    local_device_info_load();
    local_device_info_show();
    if(RF_CFG_AVAL()){
        rf_init(NULL, SLAVE_MODE_NORMAL);

        rf_config(EEPROM_get(EEPROM_OFS_HOSTID), EEPROM_get(EEPROM_OFS_DEVID));
        DBG_PRINT("slave start hostid 0x%x devid 0x%x\n", 
               EEPROM_get(EEPROM_OFS_HOSTID), EEPROM_get(EEPROM_OFS_DEVID));
        nrf_enter_rx_mode();
    }else{
#if 0
        rf_init(NULL, SLAVE_MODE_WAIT_SYNC);
        DBG_PRINT("no cfg, force device id 1, host id 0xef\n");
        rf_config(0xef, 1);
        nrf_enter_rx_mode();
#else

        rf_init(NULL, SLAVE_MODE_WAIT_DISCOVER);
        rf_config(0xc0, 0x80);
        DBG_PRINT("slave start without rf cfg\n");
#endif
    }
    sei();
    while(1){
        wdt_reset();
        rf_process();
	local_device_update();
    }
}
示例#14
0
文件: Interface.c 项目: SamChenzx/sdp
int main(void) {
// Initialize the UART,Timers, and I2C1v
    Board_init();
    Board_configure(USE_SERIAL | USE_LCD | USE_TIMER);
    dbprint("Starting encoders...\n");
    I2C_init(I2C_ID, I2C_CLOCK_FREQ);
    Encoder_init();
    Interface_init();
    Timer_new(TIMER_TEST, PRINT_DELAY );
    while (!Timer_isExpired(TIMER_TEST)) {
        Encoder_runSM();
    }

    // Not working?
    //Encoder_setZeroPitch();
    //Encoder_setZeroYaw();

    dbprint("Encoders initialized.\n");
    DELAY(STARTUP_DELAY)
    Timer_new(TIMER_TEST, PRINT_DELAY );

    bool clearedCalibrateMessage = TRUE;
    Timer_new(TIMER_TEST2,CALIBRATE_HOLD_DELAY);
    //Interface_waitLightOnTimer(CALIBRATE_HOLD_DELAY);
    Interface_waitLightOnTimer(CALIBRATE_HOLD_DELAY);

    LCD_setPosition(0,0);
    dbprint("Encoders:\n");
    while(1) {
        if (Timer_isExpired(TIMER_TEST)) {
            LCD_setPosition(1,0);
            dbprint(" P=%.1f,\n Y=%.1f\n",Encoder_getPitch(), Encoder_getYaw());

            Timer_new(TIMER_TEST, PRINT_DELAY );
        }
        if (Interface_isOkPressed() && Timer_isExpired(TIMER_TEST2)) {
            Encoder_setZeroPitch();
            Encoder_setZeroYaw();
            LCD_setPosition(3,0);
            dbprint("Zeroed encoders.\n");
            clearedCalibrateMessage = FALSE;
            Interface_waitLightOnTimer(CALIBRATE_HOLD_DELAY);
            Interface_readyLightOff();
            Timer_new(TIMER_TEST2,CALIBRATE_HOLD_DELAY);
        }
        if (Timer_isExpired(TIMER_TEST2) && !clearedCalibrateMessage) {
            clearedCalibrateMessage = TRUE;
            LCD_setPosition(3,0);
            dbprint("                     ");
            Interface_readyLightOn();
        }
        Encoder_runSM();
        Interface_runSM();
    }

    return (SUCCESS);
}
示例#15
0
void main()
{
	uint8_t MAC_Address[6] = { 0 };
	
	I2C_init(I2C1, 100000);
		delay();
	I2C_burst_read(I2C1, 0xA0, 0xFA, 6, MAC_Address);
	
	while(1);
}
示例#16
0
/*****************************************************************************
 *	\brief		test main function to run in main.c
 *	\parameters	None
 *	\return		None
 *****************************************************************************/
void test_main(){
	unsigned int n, m;
	// Initializes rx and mic buffers to zeros
	memset(audioRx, 0, N_RX*BUFLEN_8KHZ*sizeof(short));
	memset(audioMic, 0, N_MIC*BUFLEN_8KHZ*sizeof(short));
	memset(audioTx, 0, N_TX*BUFLEN_8KHZ*sizeof(short));
	memset(audioLs, 0, N_LS*BUFLEN_8KHZ*sizeof(short));

	USTIMER_init();
	I2C_init(I2C0, I2C_CLK_400K);

	// Init and config of TrueVoice
	config_true_voice_test();

	// Setup of pointers to audio buffers
	init_audio_signals_test();

	if(USE_DEBUG_PLOT) {
		// DEBUG of mixer. Run TrueVoice for TV_PLOT_LENGTH samples and dump output to files
		test_mixer();
		// DEBUG of DTMF.
		//test_dtmf();
		//DEBUG of noise reduction
		//test_noise_reduction();
		//test_fileInput();
		//DEBUG of subband functions
		//test_subband();
		//DEBUG of LEC
		//test_lec();
		//DEBUG of mute
		//test_mute();

		//Line In/Out
		//test_audio_loop();
//		TEST_audio();
//		mitt_test();
//		for(m=0;m<666;m++){ //Infinite loop
//			//Update inputBuffer
//			for(n=0; n<BUFLEN_8KHZ; n++){
//				audioMic[1][n] = n;
//			}
//
//			//Run true voice
//			true_voice(rx, mic, tx, ls);
//		}
	} else {
		// Run TrueVoice once
		//while(1){
			//simulate_capture_audio();
			//true_voice(rx, mic, tx, ls);
			//simulate_send_audio();
		//}

	}
}
示例#17
0
文件: Thermal.c 项目: sdajani/sdp
void Thermal_init(){
    I2C_init(THERMAL_I2C_ID,I2C_CLOCK_FREQ);
    count = 0;

    readEeprom();
    writeTrimmingValue();
    writeConfigReg();
    readConfigReg();
    configCalculationData();

    Timer_new(TIMER_THERMAL,READ_DELAY);
}
示例#18
0
void initializeIMU(){
	I2C_init(I2C_BASE,50000000,100000);

	I2C_start(I2C_BASE, GYROSCOPE_ADDR, 0);				//Writes to data format register of gyroscope
	I2C_write(I2C_BASE, 0x15, 0);						//to configure the sample rate of the gyroscope.
	I2C_write(I2C_BASE, 0x00, 1);

	I2C_start(I2C_BASE, GYROSCOPE_ADDR, 0);				//Writes to operation register to configure the gyroscope
	I2C_write(I2C_BASE, 0x16, 0);						//for normal operation. Also selects a low pass filter
	I2C_write(I2C_BASE, 0x18, 1);						//of 256HZ to reduce noise in gyroscope measurements.

	I2C_start(I2C_BASE, GYROSCOPE_ADDR, 0);				//Writes to power management register of gyroscope
	I2C_write(I2C_BASE, 0x3E, 0);						//to disable sleep mode and enable measurements in all axes.
	I2C_write(I2C_BASE, 0x01, 1);

	I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);			//Writes to data format register of accelerometer
	I2C_write(I2C_BASE, 0x31, 0);						//to configure the range and presentation of
	I2C_write(I2C_BASE, 0x08, 1);						//accelerometer measurements.

	I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);			//Writes to tap threshhold register to configure the accelerometer
	I2C_write(I2C_BASE, 0x1D, 0);						//for tap detection.
	I2C_write(I2C_BASE, THRESH_TAP, 1);

	I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);			//Writes to tap duration register to configure the gyroscope
	I2C_write(I2C_BASE, 0x21, 0);						//for tap detection.
	I2C_write(I2C_BASE, DUR, 1);

	I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);			//Writes to tap latency register to configure the gyroscope
	I2C_write(I2C_BASE, 0x22, 0);						//for tap detection.
	I2C_write(I2C_BASE, LATENT, 1);

	I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);			//Writes to tap window register to configure the gyroscope
	I2C_write(I2C_BASE, 0x23, 0);						//for tap detection.
	I2C_write(I2C_BASE, WINDOW, 1);

	I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);			//Writes to tap duration register to configure the gyroscope
	I2C_write(I2C_BASE, 0x2A, 0);						//for tap detection.
	I2C_write(I2C_BASE, TAP_AXES, 1);

	I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);			//Writes to tap duration register to configure the gyroscope
	I2C_write(I2C_BASE, 0x2E, 0);						//for tap detection.
	I2C_write(I2C_BASE, INT_ENABLE, 1);

	//Accel. Ctrl 2 settings
	I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);			//Writes to power management register of accelerometer
	I2C_write(I2C_BASE, 0x2D, 0);						//to disable sleep mode and enable measurements in all axes.
	I2C_write(I2C_BASE, 0x08, 1);
	//Accel. Ctrl 7 settings
	I2C_start(I2C_BASE, ACCELEROMETER_ADDR, 0);			//Writes to operation register of accelerometer
	I2C_write(I2C_BASE, 0x2C, 0);						//to configure the device bandwidth and output data rate
	I2C_write(I2C_BASE, 0x0D, 1);						//of accelerometer measurements.
}
示例#19
0
int main()
{

	// Peripheral initialisation
	I2C_init();
	LCD_init();
	LCD_write("Loading...");
	DEBUG_init();	
	
	// Function initialisation
	WAVE_init();
	synth_init();
	CAN_init();

	
	menu_display();	

	while (1)
	{
		menu_update();
	}
	
	// Keypad for synth debugging
	/*int down = 0;
	int key = -1;
	
	while(1)
	{
		key = KEYPAD_get_key();

		if ((key != -1) && !down)
		{
			int note = 69+key;
			synth_note_on(note_to_freq(note),1.0);
			LCD_write_int("%d",note_to_freq(note));
			down = 1;
		}
		if ((key == -1) && down)
		{
			synth_note_off(1.0);
			LCD_clear();
			down = 0;
		}
	}*/
	
	// Loop to allow interupts
	while(1);
	return(1);
	
}
/*
 *  ======== MSP_EXP430F5529LP_initI2C ========
 */
void MSP_EXP430F5529LP_initI2C(void)
{
    /*
     * NOTE: TI-RTOS examples configure USCIB0 as either SPI or I2C.  Thus,
     * a conflict occurs when the I2C & SPI drivers are used simultaneously in
     * an application.  Modify the pin mux settings in this file and resolve the
     * conflict before running your the application.
     */
    GPIO_setAsPeripheralModuleFunctionInputPin(
        GPIO_PORT_P3,
        GPIO_PIN0 | GPIO_PIN1);

    I2C_init();
}
示例#21
0
文件: Encoder.c 项目: BananaSlug/sdp
int main(void) {
// Initialize the UART,Timers, and I2C1v
    Board_init();
    Board_configure(USE_SERIAL | USE_LCD | USE_TIMER);
    dbprint("Check encoder addr\n");
    I2C_init(ENCODER_I2C_ID, I2C_CLOCK_FREQ);
    uint8_t pitchAddress = readDevice(SLAVE_PITCH_READ_ADDRESS,
            SLAVE_PITCH_WRITE_ADDRESS, READ_DIAGNOSTIC_ADDRESS);
    uint8_t yawAddress = readDevice(SLAVE_YAW_READ_ADDRESS,
            SLAVE_YAW_WRITE_ADDRESS, READ_DIAGNOSTIC_ADDRESS);
    dbprint("Pitch=0x%X\nYaw=0x%X\n",pitchAddress, yawAddress);

    return SUCCESS;
}
示例#22
0
文件: Magnetometer.c 项目: ddeo/sdp
int main(void) {
// Initialize the UART,Timers, and I2C1v
    Board_init();
    Serial_init();
    I2C_init(MAGNETOMETER_I2C_ID, I2C_CLOCK_FREQ);
    Magnetometer_init();
    while(1){
        Magnetometer_runSM();
        while(!Serial_isTransmitEmpty());
        printf("Angle: %.1f\n", Magnetometer_getDegree());
    }

    return (SUCCESS);
}
示例#23
0
文件: Drive.c 项目: SamChenzx/sdp
int main(){
    //Initializations
    Board_init();
    Serial_init();
    Timer_init();
    if (Drive_init() != SUCCESS) {
        printf("Failed to initialize drive module.\n");
    }
    I2C_init(TILT_COMPASS_I2C_ID, I2C_CLOCK_FREQ);
    if (TiltCompass_init() != SUCCESS) {
        printf("Failed to initialize tilt compass module.\n");
    }
    ENABLE_OUT_TRIS = OUTPUT;

    while (1) {
        printf("Driving north at full speed.\n");
        Timer_new(TIMER_TEST, COMMAND_DELAY);
        Drive_forwardHeading(100, 0);

        while(!Timer_isExpired(TIMER_TEST)) {
            //wait for finish
            DELAY(1);
            Drive_runSM();
            TiltCompass_runSM();
        }
        Drive_stop();
        Drive_runSM();
        TiltCompass_runSM();

        printf("Driving south at full speed.\n");
        Timer_new(TIMER_TEST, COMMAND_DELAY);
        Drive_forwardHeading(100, 180);

        while(!Timer_isExpired(TIMER_TEST)) {
            //wait for finish
            DELAY(1);
            Drive_runSM();
            TiltCompass_runSM();
        }
        
        Drive_stop();
        Drive_runSM();
        TiltCompass_runSM();
        delayMillisecond(COMMAND_DELAY);
        printf("Waiting for retry...\n");

    }

    return SUCCESS;
}
int main(void) {
    init();
    I2C_init();
    int i = 0;
    unsigned short average[5] = {0};
    unsigned short average_ans = 0;
    while (1) {
        for( i = 0;i < 5;i++){
            TRISA0 = 0;         //OUTPUT
            RA0 = 0;            //LOW
            __delay_us(2);
            RA0 = 1;            //HIGH
            __delay_us(5);
            RA0 = 0;            //LOW

            TRISA0 = 1;
            if(RA0 == 1){
                TMR1L = 0;
                TMR1H = 0;
                TMR1IF = 0;
                count_time = 0;
                while(RA0 == 1){
                    if(TMR0IF){
                        count_time += 65536;
                        TMR1IF = 0;
                    }
                    if(count_time > 30000) break;
                }
                if(TMR1IF){
                    count_time += TMR1 + 65536;
                }else{
                    count_time += TMR1;
                }
                count_time = count_time / 6.169463087248322;
                average[i] = count_time;
                __delay_ms(1);
            }
        }
        for( i = 0; i < 5; i++){
            average_ans += average[i];
        }
        average_ans = average_ans / 5;
        if(count_time > 4000) count_time = 4000;
        else if(count_time < 20) count_time = 0;
        send_data[0] = average_ans % 0x100;
        send_data[1] = average_ans / 0x100;
    }
    return (0);
}
示例#25
0
/*
 *  ======== MSP_EXP432P401R_initI2C ========
 */
void MSP_EXP432P401R_initI2C(void)
{
    /*
     * NOTE: TI-RTOS examples configure EUSCIB0 as either SPI or I2C.  Thus,
     * a conflict occurs when the I2C & SPI drivers are used simultaneously in
     * an application.  Modify the pin mux settings in this file and resolve the
     * conflict before running your the application.
     */
    /* Configure Pins 1.6 & 1.7 as SDA & SCL, respectively. */
    MAP_GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P1,
        GPIO_PIN6 | GPIO_PIN7, GPIO_PRIMARY_MODULE_FUNCTION);

    /* Initialize the I2C driver */
    I2C_init();
}
示例#26
0
文件: main.c 项目: fabsat/dsPIC_I2C
/***********************************************************
 * メイン関数
 ***********************************************************/
int main(void){
    unsigned int i;
    //unsigned char c;
    I2C_init();
    I2CBRG = 0x01;
    I2CADD = 0x09;
    i = I2C_read_int(0x04);
    //c = I2C_read_char(0x04);
    //I2C_send_char(0x04, c);
    //I2C_send_int(0x04, 1234);
    while(1){
    }

    return 0;
}
void main( void ) 
{
	I2C_init();
	Sampling(SAMPLES_PER_SECOND, ADCgain);

	while(1){

     left_input = 	generate_sinewave_L(250, 10000);
     right_input = generate_sinewave_R(250, 10000);

     //filter input
 	 left_output = FIR_filter_asm(&hp[0], left_input);
     right_output = FIR_filter_asm_2(&hp[0], right_input);
     codec_write(left_output, right_output);
	}
}
/*******************************************************************************
 * @fn          i2c_inicia
 * @brief       Inicia i2c
 */
bool i2c_inicia(void)
{
  I2C_init();
  I2C_Params_init(&i2cParams);
  i2cParams.bitRate = I2C_400kHz;
  i2cHandle = I2C_open(Board_I2C, &i2cParams);

  slaveAddr = 0xFF;
  interface = 0;

  if (i2cHandle == NULL)
  {
    return false;
  }
  return true;
}
示例#29
0
static int __init mod_init(void)
{
	printk("hello MOD\n");
	result = register_chrdev(0,"MOD",&mod_fops);	
	printk(" $ sudo mknod /dev/MOD c %d 0\n",result);
	// Get register address

        gpio_reg = (uint32_t*) ioremap(GPIO_BASE, GPIO_LEN);	
	i2c_reg  = (uint32_t*) ioremap(BSC_BASE, BSC_LEN);
	I2C_init();
	
	MPU6050_Reg_setup();

	return 0;

}
int main(void)
{
        I2C_init(I2C_SPEED);                 //init i2c master for 100k
        init_time_sd();
        vSemaphoreCreateBinary( event_signal ); // Create the semaphore
        xSemaphoreTake(event_signal, 0);        // Take semaphore after creating it.
        scheduler_add_task(new terminalTask(PRIORITY_HIGH));
        TaskHandle_t test1 = NULL;
        xTaskCreate((void(*)(void *))read_from_slave, "i2c_receive_task", 1024, NULL, PRIORITY_HIGH, &test1);
        eint3_enable_port2(0,eint_rising_edge,data_avail_isr);   //register for rising edge interrupt
        scheduler_add_task(new send_CAN_data(PRIORITY_MEDIUM));
        scheduler_add_task(new send_mailbox_config(PRIORITY_MEDIUM));
        scheduler_add_task(new sendTrigTask()); //Task for getting the sensor data
        scheduler_start(); ///< This shouldn't return
        return -1;
}