int i2c_setup() { memcpy(I2C, I2CInit, sizeof(I2CInfo) * (sizeof(I2C) / sizeof(I2CInfo))); init_i2c(&I2C[0]); init_i2c(&I2C[1]); init_i2c(&I2C[2]); return 0; }
uint8_t init_speedy(void){ uint8_t data = 0x00; //Init I2C 1 if(init_i2c(I2C_1) != 0) return 1; //Pyro Sensor if(write_i2c(I2C_1, ADDR_TPA81, &data, 1) != 1) return 11; //SRF08 hinten links if(write_i2c(I2C_1, SRF_HL, &data, 1) != 1) return 12; //SRF08 vorne if(write_i2c(I2C_1, SRF_V, &data, 1) != 1) return 13; //SRF08 hinten rechts if(write_i2c(I2C_1, SRF_HR, &data, 1) != 1) return 14; //Init I2C 2 if(init_i2c(I2C_2) != 0) return 2; //HMC6343 if(write_i2c(I2C_2, ADDR_HMC, &data, 1) != 1) return 21; //MAX11613 if(write_i2c(I2C_2, ADDR_MAX11613, &data, 1) != 1) return 22; //LCD if(write_i2c(I2C_2, LCD03_ADRESS, &data, 1) != 1) return 23; //ITG3200 if(write_i2c(I2C_2, ADDR_ITG, &data, 1) != 1) return 24; //Init Motor Modul if(init_itg() != 0) return 3; //Init G Sensor ADXL345 on DE0 Nano SoC if(!ADXL345_Init()) return 4; return 0; }
int main(int argc, char **argv) { int result,i; int i2c_fd; i2c_fd=init_i2c("/dev/i2c-1"); if (i2c_fd < 0) { fprintf(stderr,"Error opening device!\n"); return -1; } /* Init display */ if (init_display(i2c_fd,HT16K33_ADDRESS0,10)) { fprintf(stderr,"Error opening display\n"); return -1; } result=load_font("tbfont.tb1"); while(1) { for(i=32;i<127;i++) { result=put_letter(i,i2c_fd); usleep(500000); } } return result; }
PUBLIC void setupHardware(void) { //inicializa as configuraçoes do micrococontrolador init_mcu(); //Inicializa driver das interrupcoes interrupt_init(); //Inicializa as portas do microcontrolador init_gpio(); //Inicializa UART init_uart(); //Inicializa TMR0 init_timer0(); //Inicializa I2C init_i2c(); //Inicializa ADs init_AD(); //Inicializa PWM init_pwm(); }
int main(int argc, char **argv) { int i, v; byte data[20]; init_i2c("/dev/i2c-1"); // set mode register to 1 to activate accelerometer data[0] = 7; data[1] = 1; I2cSendData(MMA7660_ADDR,data,2); printf("Hit any key to quit\n\n"); while (1) { I2cReadData(MMA7660_ADDR,data,11); for (i=0; i<3; i++) { v = (data[i]/2^6)*9.81; if (v>=0x20) v = -(0x40 - v); //sign extend negatives printf("%c:%3d ",i+'X',v); } for (i=3; i<11; i++) printf("%x: %02x ",i,data[i]); printf("\r"); } printf("\n"); close(deviceDescriptor); return 0; }
void initialisation(void) { //ADC Off ADCON0bits.ADON = 0; ADCON1 = 0b00001111; //Définition des IO define_i_o(); //Périphériques // init_timer_0(); config_port_b(); init_i2c(); init_eusart(); //config_euart(); //Init GLCD GLCD_Initalize(); Delay10KTCYx(0); //Modifier? GLCD_ClearScreen(); // On autorise toutes les interruptions RCONbits.IPEN = 0; //1 niveau INTCONbits.GIE = 1; INTCONbits.PEIE = 1; }
int16_t main(void) { init_clock(); init_ui(); init_pin(); init_timer(); init_i2c(); InitUSB(); init_oc(); init_display(&i2c3, 0x70, 0x71); init_game(&timer1, &timer2, &A[0], &disp1, &disp2); init_gun(&D[13], &A[1], &A[2], &timer3); init_launcher(&D[5], &D[8], &D[3], &D[4]); init_shooter(&D[6], &D[9], &D[1], &D[2], &D[7], &D[0], &oc3, &oc4); init_baller(&D[10], &oc2, &timer4, &shooter, &launcher); init_pix(&D[11], &timer5, 30, 0.05); init_audio(&D[12]); uint8_t level = 0; uint8_t hit_flag = 0; while (1) { ServiceUSB(); // usb times out if not checked fast enough :/ level = run_game(hit_flag); ServiceUSB(); hit_flag = run_gun(level); ServiceUSB(); run_baller(level); } }
int main (void) { uint8_t data = 0; uint32_t len = 0; //SystemClockUpdate(); SystemCoreClockUpdate(); init_i2c(); uart2_init(115200, CHANNEL_A); // Control de flujo: NINGUNO DACInit(); uart2_sendString((uint8_t*)"\r\nModulador PSK\r\n"); while (1) { len = uart2_receive(&data, 1, FALSE); if (len > 0) { uart2_send(&data, 1); procesarBytes(data); } Timer0_Wait(50); } }
int main(void) { DDRC |= (1 << DDRC7); PORTC |= (1 << PORTC7); _delay_ms(2); PORTC &= ~(1 << PORTC7); init_power(); init_timeout_timer(); init_switch(); init_ref_clock(); init_spi(2); init_buttons(); init_serial(2400); init_adc(); init_i2c(); //Turn on interrupts sei(); play_sounds(); //Debug: Never Gets here while(1) { _delay_ms(1000); get_POT_set_TWIPOT(); } }
int main(int argc, char ** argv){ char c ; FILE * fr; long start_time, end_time ; double diff_time ; struct timespec cpu_time ; unsigned int size = 0 ; initGPIOs(); #ifdef MARK1 init_i2c(3); #endif fr = fopen (argv[1], "rb"); /* open the file for reading bytes*/ if(fr < 0){ printf("cannot open file %s \n", argv[1]); } size = fread(configBits, 1, 1024*1024, fr); printf("bit file size : %d \n", size); //clock_gettime(CLOCK_REALTIME, &cpu_time); //start_time = cpu_time.tv_sec ; if(serialConfig(configBits, size) < 0){ printf("config error \n"); exit(0); }else{ printf("config success ! \n"); } //clock_gettime(CLOCK_REALTIME, &cpu_time); //end_time = cpu_time.tv_sec ; //diff_time = end_time - start_time ; //diff_time = diff_time/1000000 ; //printf("Configuration took %fs \n", diff_time); closeGPIOs(); fclose(fr); return 1; }
int16_t main(void) { // printf("Starting Rocket Controller...\r\n"); init_clock(); init_ui(); init_pin(); init_timer(); init_i2c(); setup(); init_servo_driver(&sd1, &i2c3, 16000., 0x0); init_servo(&servo4, &sd1, 0); InitUSB(); U1IE = 0xFF; //setting up ISR for USB requests U1EIE = 0xFF; IFS5bits.USB1IF = 0; //flag IEC5bits.USB1IE = 1; //enable // uint32_t pid_command; servo_set(&servo4, 1500, 0); while (1) { if (timer_flag(&timer1)) { // Blink green light to show normal operation. timer_lower(&timer1); led_toggle(&led2); // servo_set(&servo4, 1500, 0); } } }
void i2c_detect() { printf("Trying to detect any i2c slaves...\n\r"); uint8_t addr = 0; int i; while (1) { init_i2c(); i=40000; while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); I2C_GenerateSTART(I2C1, ENABLE); while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2C1, addr++, I2C_Direction_Transmitter); while (1) { if (I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { printf("Found something @ %hhx\n\r",addr); break; } i--; if (!i) { printf("NACK @ %hhx\n\r",addr); break; } } } }
int aiao_codec_init(void) { int ret = 0; godbox_aic31_reset(); init_i2c(); return ret; }
static int init_wrauxr(struct nvbios_init *init, u32 addr, u8 data) { struct nouveau_i2c_port *port = init_i2c(init, -2); if (port && init_exec(init)) return nv_wraux(port, addr, &data, 1); return -ENODEV; }
static int init_wri2cr(struct nvbios_init *init, u8 index, u8 addr, u8 reg, u8 val) { struct nouveau_i2c_port *port = init_i2c(init, index); if (port && init_exec(init)) return nv_wri2cr(port, addr, reg, val); return -ENODEV; }
/** * Write a single byte to a register of the accelerometer * *@param reg register value of the accelerometer *@param buffer containing the the value of the register * *@return the status 0= Failure Others= Success */ uint8_t st_LIS3LwriteSingleRegister(uint8_t reg, uint8_t* buffer) { init_i2c(); if (msp430_i2c_write(I2C_START,LIS3L_I2C_ADDRESS, 1, ®)!=0) return msp430_i2c_write(I2C_STOP,LIS3L_I2C_ADDRESS, 1, buffer); else return 0; //Failure }
uint8_t Init_IMU(void){ init_i2c(); __delay_cycles(800); if (initGyro()){return 1;} __delay_cycles(800); if (initXM()){return 1;} __delay_cycles(800); return 0; }
int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop WDT PM5CTL0 &= ~LOCKLPM5; //Set clock speed CSCTL0_H = CSKEY >> 8; // Unlock CS registers CSCTL1 = DCOFSEL_6; // Set DCO to 8MHz CSCTL2 = SELA__VLOCLK | SELS__DCOCLK | SELM__DCOCLK; // Set SMCLK = MCLK = DCO // ACLK = VLOCLK CSCTL3 = DIVA__1 | DIVS__1 | DIVM__1; // Set all dividers to 1 CSCTL0_H = 0; // Lock CS registers //Set clock speed rate_gyr_x = 0; rate_gyr_y = 0; rate_gyr_z = 0; init_i2c(); initGyro(); initXM(); while (1) { ////////////READ GYROSCOPE////////////// xRate_L = single_byte_read_i2c(gyro_Address, OUT_X_L_G); xRate_H = single_byte_read_i2c(gyro_Address, OUT_X_H_G); yRate_L = single_byte_read_i2c(gyro_Address, OUT_Y_L_G); yRate_H = single_byte_read_i2c(gyro_Address, OUT_Y_H_G); zRate_L = single_byte_read_i2c(gyro_Address, OUT_Z_L_G); zRate_H = single_byte_read_i2c(gyro_Address, OUT_Z_H_G); /////////////READ ACCELEROMETER///////////////// xaccel_L = single_byte_read_i2c(XMAddress, OUT_X_L_A); xaccel_H = single_byte_read_i2c(XMAddress, OUT_X_H_A); yaccel_L = single_byte_read_i2c(XMAddress, OUT_Y_L_A); yaccel_H = single_byte_read_i2c(XMAddress, OUT_Y_H_A); zaccel_L = single_byte_read_i2c(XMAddress, OUT_Z_L_A); zaccel_H = single_byte_read_i2c(XMAddress, OUT_Z_H_A); ////////////////CONVERT TO MEANINGFUL DATA////////////////////// gyrRawx = (xRate_L | xRate_H << 8); gyrRawy = (yRate_L | yRate_H << 8); gyrRawz = (zRate_L | zRate_H << 8); rate_gyr_x = gyrRawx * G_GAIN; rate_gyr_y = gyrRawy * G_GAIN; rate_gyr_z = gyrRawz * G_GAIN; accRawx = (xaccel_L | xaccel_H << 8); accRawy = (yaccel_L | yaccel_H << 8); accRawz = (zaccel_L | zaccel_H << 8); g_x = (accRawx * A_GAIN) / thousand; g_y = (accRawy * A_GAIN) / thousand; g_z = (accRawz * A_GAIN) / thousand; } }
void airdrums_stick(void){ //initial setup WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1SEL &= 0; P1SEL2 &= 0; P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0 P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0 // LED pin P1DIR |= 0x01; P1OUT = 0x00; // start up i2c bus init_i2c(); //intialise some globals highCount = 0; isDown = FALSE; driftCount=0; // Give the nrf plenty of time to start up; // it gets pissy if you talk to it too early. __delay_cycles(10000); nrfInit(); __delay_cycles(10000); // Start TX with address '!'. // Hard coded because why not nrfStartTX('!'); __delay_cycles(10000); //transmit stuff to set up mpu6050 //set sensitivity levels MPU6050_write_byte(MPU6050_GYRO_CONFIG, MPU6050_FS_SEL_2000); MPU6050_write_byte(MPU6050_ACCEL_CONFIG, MPU6050_AFS_SEL_16G); //wake sensor up by clearing sleep bit MPU6050_write_byte (MPU6050_PWR_MGMT_1, 0); // initialise circular buffer circ_init(); // Do some quick and dirty drift correction findDrift(); // Set up timer interrupts for main loop CCTL0 = CCIE; // CCR0 interrupt enabled TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK/8, upmode CCR0 = (1000000 / 8 / PROCESS_RATE_HZ); // Set process rate // CCR0 = 417; // 300 Hz _BIS_SR(CPUOFF + GIE); // Enter LPM0 w/ interrupt while(1); }
void init_all(void) { init_uart(); init_pll(); act8600_setting(); init_ddr(); // init_lcd(); init_i2c(); // init_pwm(); }
int main(int argc, char ** argv) { if(argc < 2) { fprintf(stderr, "Usage: %s <device>\n", argv[0]); return -1; } // int fd = init_rs232(argv[1]); int fd = init_i2c(argv[1], 0x48); uint8_t value[2]; struct i2c_cmd cmd; // cmd.i2c_cmd = 0x55; // cmd.i2c_addr = 0x91; cmd.i2c_reg = 0x00; // cmd.i2c_bytes = 2; while(true) { struct timespec time_before, time_after; clock_gettime(CLOCK_MONOTONIC, &time_before); const int write_ret = write(fd, (void *)&cmd, sizeof(cmd)); const int read_ret = read(fd, (void *)value, 2); // value[0] = 0x1a; // value[1] = 0xf0; if(read_ret < 0) { printf("Error on read(fd, value, 2): %d %s\n", errno, strerror(errno)); continue; } const uint16_t value_ntohs = (value[1] >> 4) | (value[0] << 4); uint16_t value_twosc = value_ntohs; if(value_ntohs & 0x0800) { value_twosc = value_ntohs - 1; value_twosc ^= 0xfff; } const float value_float = ((float)value_twosc) * 0.0625; clock_gettime(CLOCK_MONOTONIC, &time_after); printf( "%09d,%09d,%09d,%09d,%06d,%f\n", time_before.tv_sec, time_before.tv_nsec, time_after.tv_sec, time_after.tv_nsec, value_twosc, value_float); fflush(stdout); sleep(1); } return 0; };
/** * Write multiple bytes (registers) in the accelerometer * *@param reg register value of the accelerometer from where the writing will get started *@param count number of the bytes to be written *@param buffer storing the bytes to be written * *@return the status 0= Failure Others= Success */ uint8_t st_LIS3LwriteMultipleRegisters(uint8_t reg,uint8_t count, uint8_t* buffer ) { uint8_t modified_reg; init_i2c(); modified_reg= fixAddress(count,reg); if (msp430_i2c_write(I2C_START,LIS3L_I2C_ADDRESS, 1,&modified_reg)!=0) return msp430_i2c_write(I2C_STOP,LIS3L_I2C_ADDRESS, count, buffer); else return 0; //Failure }
void main(void) { DDRC = 0xff; PORTC = 0xff; unsigned char ch,ch1; unsigned char buf[10]; uart1_init(); lcd_init(); lcd_char('*'); init_i2c(); WR_I2C(0,0x57);//Sec WR_I2C(1,0x59);//Min WR_I2C(2,0x11 | (1<<5)|(1<<6) );//Hr WR_I2C(3,1);//Day WR_I2C(4,0x31);//Date WR_I2C(5,0x12);//Month WR_I2C(6,0x99);//year while(1) { ch = RD_I2C(0,0);//sec sprintf(buf,"\n\rSec = %02d",Hex2Dec(ch)); uart1_transmit_string(buf); ch = RD_I2C(1,0);//min sprintf(buf,"\n\rMin = %02d",Hex2Dec(ch)); uart1_transmit_string(buf); ch = RD_I2C(2,0);//hr sprintf(buf,"\n\rHr = %02d",Hex2Dec( ch & 0x1F ) ); uart1_transmit_string(buf); ch = RD_I2C(3,0);//day sprintf(buf,"\n\rDay = %02d",Hex2Dec(ch)); uart1_transmit_string(buf); ch = RD_I2C(4,0);//date sprintf(buf,"\n\rDate = %02d",Hex2Dec(ch)); uart1_transmit_string(buf); ch = RD_I2C(5,0);//month sprintf(buf,"\n\rMonth = %02d",Hex2Dec(ch)); uart1_transmit_string(buf); ch = RD_I2C(6,0);//year sprintf(buf,"\n\rYear = %02d",Hex2Dec(ch)); uart1_transmit_string(buf); _delay_ms(1000); } }
int main() { DLN_RESULT result; DlnConnect("localhost", DLN_DEFAULT_SERVER_PORT); // Check device count uint32_t device_count; result = DlnGetDeviceCount(&device_count); if (!DLN_SUCCEEDED(result)) { std::cout << "Failed to get DLN device count" << std::endl; return -1; } if (device_count != 1) { std::cout << "There should be one and only one DLN device connected. There are " << device_count << std::endl; return -1; } // Try to open our device HDLN handle; result = DlnOpenDevice(0, &handle); if (!DLN_SUCCEEDED(result)) { std::cout << "Failed to open DLN device" << std::endl; return -1; } // Print out some info about our DLN device DLN_VERSION version; uint32_t sn, id; DlnGetVersion(handle, &version); DlnGetDeviceSn(handle, &sn); DlnGetDeviceId(handle, &id); std::cout << "Opened DLN device: " << sn << "\t" << id << std::endl; // Initialize all the things init_i2c(handle); init_analog(handle); // Instantiate the rover controller RoverControl rover(handle); while (true) { rover.update(); } cleanup_analog(handle); DlnCloseHandle(handle); DlnDisconnectAll(); return 0; }
int main(int argc, char **argv) { int i; byte data[2]; init_i2c("/dev/i2c-0"); I2cReadData(0x38,data,1); printf("data1 %x\n",data[0]); printf("data2 %x\n",data[1]); printf("data3 %x\n",data[2]); return 0; }
/** Enable of disable the I2C Bus * * *@param newMode holds the value to set or clear the I2C bus mode * */ uint8_t dev_mode_DEV_MSP_ACCELEROMETER(uint8_t newMode) { switch (newMode) { case DEV_MODE_ON: init_i2c(); break; case DEV_MODE_OFF: msp430_i2c_clearModeI2C(); break; default: return DEV_UNSUPPORTED; } return DEV_OK; }
static int init_rdauxr(struct nvbios_init *init, u32 addr) { struct nouveau_i2c_port *port = init_i2c(init, -2); u8 data; if (port && init_exec(init)) { int ret = nv_rdaux(port, addr, &data, 1); if (ret) return ret; return data; } return -ENODEV; }
void init_all() { init_gpio(); pwm_init(); adc_init(); init_all_pulse_counter(); LPLD_Flash_Init(); init_sdhc(); //SD卡模块初始化 uart_interr_init(); init_i2c(); //MPU6050初始化 //LPLD_MMA8451_Init(); OLED_Init(); pit_init(); init_paranum(); init_setpara(); init_readpara(); save.g_s16SDDenoteNum = 0;//防止不小心保存非0数 }
int main() { init_timer(); init_ATX_power(); init_serial(); init_stdio(); init_safety_switches(); init_i2c(); init_laser_power(); init_heaters(); init_main_laser(); sei(); enable_ATX_power(); uint32_t b = millisecond_time(); while (!ATX_power_state()) { enable_ATX_power(); continue; } uint32_t a = millisecond_time(); printf("ATX power: %ld msec\n", a - b); enable_heater_1(); // aka water pump delay_milliseconds(2000); enable_heater_0(); // aka high voltage supply set_laser_power(4095 / 3); // 1/3rd power printf("Main Laser! Danger!\n"); while (true) { if (getchar() == '\r') { if (e_is_stopped()) printf("Emergency Stop. No fire.\n"); else if (lid_is_open()) printf("Lid is open. No fire.\n"); else { printf("Fire!\n"); enable_main_laser(); delay_milliseconds(PULSE_MS); disable_main_laser(); } } } }
/* Main */ void main() { unsigned short int count = 0; unsigned char data; /* Allow peripheral init */ delay(1000); /* Initialize PIC USART to operate at 19200 baud */ init_serial(); /* Initialize I2C */ init_i2c(); /* Turn ON and setup up LCD */ init_lcd(); /* Loop reception and echo it back */ receive_next: while(!PIR1bits.RCIF); /* Echo received character */ data = RCREG; TXREG = data; /* Send the received byte to EEPROM */ write_to_eeprom(data, count); count++; if(count == 16) { dump_to_lcd(); count = 0; } goto receive_next; /* Shouldn't get here! */ while(1); }