Ejemplo n.º 1
0
void systemInit(void)
{
	// Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    ///////////////////////////////////

    checkFirstTime(false);
	readEEPROM();

	if (eepromConfig.receiverType == SPEKTRUM)
		checkSpektrumBind();

	checkResetType();

	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  // 2 bits for pre-emption priority, 2 bits for subpriority

	initMixer();

    ledInit();
    cliInit();

    BLUE_LED_ON;

    delay(20000);  // 20 sec total delay for sensor stabilization - probably not long enough.....

    adcInit();
    batteryInit();
    gpsInit();
    i2cInit(I2C1);
    i2cInit(I2C2);
    pwmEscInit(eepromConfig.escPwmRate);
    pwmServoInit(eepromConfig.servoPwmRate);
    rxInit();
    spiInit(SPI2);
    spiInit(SPI3);
    telemetryInit();
    timingFunctionsInit();

    initFirstOrderFilter();
    initGPS();
    initMax7456();
    initPID();

    GREEN_LED_ON;

    initMPU6000();
    initMag(HMC5883L_I2C);
    initPressure(MS5611_I2C);
}
Ejemplo n.º 2
0
static void i2c_er_handler(void)
{
    // Read the I2Cx status register
    uint32_t SR1Register = I2Cx->SR1;

    if (SR1Register & 0x0F00) {                                         // an error
        error = true;
    }

    // If AF, BERR or ARLO, abandon the current job and commence new if there are jobs
    if (SR1Register & 0x0700) {
        (void)I2Cx->SR2;                                                // read second status register to clear ADDR if it is set (note that BTF will not be set after a NACK)
        I2C_ITConfig(I2Cx, I2C_IT_BUF, DISABLE);                        // disable the RXNE/TXE interrupt - prevent the ISR tailchaining onto the ER (hopefully)
        if (!(SR1Register & 0x0200) && !(I2Cx->CR1 & 0x0200)) {         // if we dont have an ARLO error, ensure sending of a stop
            if (I2Cx->CR1 & 0x0100) {                                   // We are currently trying to send a start, this is very bad as start, stop will hang the peripheral
                // TODO - busy waiting in highest priority IRQ. Maybe only set flag and handle it from main loop
                while (I2Cx->CR1 & 0x0100) { ; }                        // wait for any start to finish sending
                I2C_GenerateSTOP(I2Cx, ENABLE);                         // send stop to finalise bus transaction
                while (I2Cx->CR1 & 0x0200) { ; }                        // wait for stop to finish sending
                i2cInit(I2Cx_index);                                    // reset and configure the hardware
            } else {
                I2C_GenerateSTOP(I2Cx, ENABLE);                         // stop to free up the bus
                I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, DISABLE);   // Disable EVT and ERR interrupts while bus inactive
            }
        }
    }
    I2Cx->SR1 &= ~0x0F00;                                               // reset all the error bits to clear the interrupt
    busy = 0;
}
Ejemplo n.º 3
0
int main(void) 
{   
    // (Using SDA1 and SCL1
    // Configure I2C Port
    i2cInit(1,157);
    delay_ms(500);
    while(1)
    {
        // Start bit + Address + read or write bit
        i2c1StartAddress(I2Caddr, 0); //(7-seg address, write (0))
        // Data + Ack
        i2c1WriteByte(clrDisplay);
        i2c1WriteByte('1');
        i2c1WriteByte('2');
        i2c1WriteByte('3');
        i2c1WriteByte('4');
        // Stop Bit
        i2c1Stop();
        delay_ms(1000);
        
        // Start bit + Address + read or write bit
        i2c1StartAddress(I2Caddr, 0); //(7-seg address, write (0))
        // Data + Ack
        i2c1WriteByte(clrDisplay);
        i2c1WriteByte('a');
        i2c1WriteByte('5');
        i2c1WriteByte('d');
        i2c1WriteByte('b');
        // Stop Bit
        i2c1Stop();
        delay_ms(1000);
    }
    return (EXIT_SUCCESS);
}
Ejemplo n.º 4
0
error_t smb380Init(void)
{
   error_t error;
   uint8_t value;

   //Debug message
   TRACE_INFO("Initializing SMB380...\r\n");

   //I2C initialization
   i2cInit();

   //Read chip ID
   error = smb380ReadReg(SMB380_REG_CHIP_ID, &value);
   //Any error to report?
   if(error) return error;

   //Verify chip identifier
   if((value & CHIP_ID_MASK) != CHIP_ID_VERSION_2)
      return ERROR_INVALID_VERSION;

   //Read version register
   error = smb380ReadReg(SMB380_REG_VERSION, &value);
   //Any error to report?
   if(error) return error;

   //Select +/-2g range and 25Hz bandwidth
   value = CTRL3_RANGE_2G | CTRL3_BANDWIDTH_25HZ;
   //Write configuration to SMB380 device
   error = smb380WriteReg(SMB380_REG_CTRL3, value);
   //Any error to report?
   if(error) return error;

   //Successful initialization
   return NO_ERROR;
}
Ejemplo n.º 5
0
int
main(void)
{
  uint16_t ui1;

  LCD_init();
  i2cInit();
  Timer_Init();
  KbdInit();

  LCD_busy
  LCD_CLRSCR

  LCD_WR_LINE(0, 0, "Starting!!!");
  for (ui1=0; ui1<0x3F; ui1++)
    LCD_busy;

  LCD_WR_LINE(0, 0, "Press any key!!!");
  LCD_WR_LINE(1, 0, "Shall displayed!");
  KBD_RESET_KEY;
  while (1) {
    KBD_GET_KEY;
    LCD_POS(1, 0);
    LCD_WR("Scan Code : ");
    LCD_PUT_UINT8X(KbdData);
    for (ui1=0; ui1<0xFF; ui1++)
      {}
    KBD_RESET_KEY;
  }

  return 0;
}
Ejemplo n.º 6
0
int
main(void)
{
	struct ds1307_t rtc_tm;

	static const char infostring[] PROGMEM = "Demo - DS1307 RTC\r\n";
	char buffer[BUFFER_SIZE];

	uartInit(BAUDRATE);
	i2cInit(I2C_STD_MODE);
	sei();

	ds1307Init();
	ds1307SetTime(SYS_HOUR, SYS_MINS, SYS_SECS);
	ds1307SetDate(SYS_DAY, SYS_MONTH, SYS_YEAR);

	uartPutString_P(infostring);

	while (1) {
		/* Read Current Time from DS1307 and output to UART */
		ds1307GetTime(&rtc_tm);
		sprintf(buffer, "RTC: [%02d:%02d:%02d] - [%02d.%02d.%02d]\r\n",
		    rtc_tm.hours, rtc_tm.minutes, rtc_tm.seconds, rtc_tm.day,
		    rtc_tm.month, rtc_tm.year);
		uartPutString(buffer);
		_delay_ms(1000);
	}

	/* never reached */
	return (0);
}
Ejemplo n.º 7
0
// Any PIC initialization that is necessary goes here
void Initialise()
{
    FLAG    = 0;            // Clear everything first
    beginPWM();             // initialize PWM associated registers
    setPWM(0);              // Set PWM to 0 until Arduino say otherwise
    i2cInit(I2C_ADDRESS);   // initialize I2C
    PEIE    = 1;            // generic peripheral interrupts enabled
    PIE1    = 0b00001000;   // I2C interrupts enabled
    SSPIF   = 0;            // Clear I2C flag
    GIE     = 1;            // Enable all interrupts

    beginEncoder();         // initialize encoder registers (TMR0 & TMR1)
    PIE2    = 0;            // other peripherals disabled

// Clear and Initate TIMER registers
    TMR1    = 0;
    TMR0    = 61;           // Preset TMR0 so that it will overflow every 10 ms
// Configure interrupts
    RBIE    = 1;            // PORTB interrupts enabled
    T0IE    = 1;            // TMR0 interrupts enabled
    TMR1IE  = 1;            // TMR1 interrupts enabled
    // Clear flags
    RBIF    = 0;
    T0IF    = 0;
    TMR1IF  = 0;
// Turn on I/Os
    TRISB   = 0b11110111;
    PORTBbits.RB3 = FORWARD;    // default to forward
    TRISD   = 0;
    PORTD   = 0;
    PORTCbits.RC1 = 0;
}
Ejemplo n.º 8
0
void ds1307Init(void)
{
	i2cInit();
	ds1307EnableOscillator();
	ds1307SetHourMode(kDS1307Mode24HR);
	ds1307SetSquarewaveOutput(DS1307_SQUAREWAVE_ENABLE, DS1307_RATE_1HZ);
}
isl12022mError_t isl12022mInit(void)
{
  isl12022mError_t error = ISL12022M_ERROR_OK;
  uint8_t buffer[1];

  // Initialise I2C
  if (i2cInit(I2CMASTER) == false)
  {
    return ISL12022M_ERROR_I2C_INIT;    /* Fatal error */
  }
  
  // Make sure write is enabled on the ISL12202M (factory default = disabled)
  error = isl12022mReadBuffer(ISL12022M_RTC_ADDRESS, ISL12022M_REG_CSR_INT, buffer, sizeof(buffer));
  if (!error)
  {
    if (!(buffer[0] & ISL12022M_INT_WRITEENABLE))
    {
      // Write is not enabled on the RTC ... enable it now
      error = isl12022mWrite8(ISL12022M_RTC_ADDRESS, ISL12022M_REG_CSR_INT, buffer[0] | ISL12022M_INT_WRITEENABLE);
    }
    _isl12022mInitialised = true;
  }

  return error;
}
Ejemplo n.º 10
0
bool i2cRead(I2C_TypeDef *I2C, uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t *buf)
{
    uint32_t timeout = I2C_DEFAULT_TIMEOUT;

    I2Cx = I2C;

    addr = addr_ << 1;
    reg = reg_;
    writing = 0;
    reading = 1;
    read_p = buf;
    write_p = buf;
    bytes = len;
    busy = 1;

    if (!(I2Cx->CR2 & I2C_IT_EVT))                                      // If we are restarting the driver
    {
        if (!(I2Cx->CR1 & I2C_CR1_START))                               // Ensure sending a start
        {
            while (I2Cx->CR1 & I2C_CR1_STOP) { ; }                      // Wait for any stop to finish sending
            I2C_GenerateSTART(I2Cx, ENABLE);                            // Send the start for the new job
        }
        I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, ENABLE);            // Allow the interrupts to fire off again
    }

    while (busy && --timeout > 0);
    if (timeout == 0) {
        if (I2Cx == I2C1) i2c1ErrorCount++;
        if (I2Cx == I2C2) i2c2ErrorCount++;
        i2cInit(I2Cx);                                                  // Reinit peripheral + clock out garbage
        return false;
    }

    return true;
}
Ejemplo n.º 11
0
void I2C_ER_Handler(void)
{
    volatile uint32_t SR1Register, SR2Register;

    SR1Register = I2Cx->SR1;                                              // Read the I2Cx status register

    if (SR1Register & (I2C_SR1_AF   |
                       I2C_SR1_ARLO |
                       I2C_SR1_BERR ))                                    // If AF, BERR or ARLO, abandon the current job and commence new if there are jobs
    {
        SR2Register = I2Cx->SR2;                                          // Read second status register to clear ADDR if it is set (note that BTF will not be set after a NACK)
        I2C_ITConfig(I2Cx, I2C_IT_BUF, DISABLE);                          // Disable the RXNE/TXE interrupt - prevent the ISR tailchaining onto the ER (hopefully)
        if (!(SR1Register & I2C_SR1_ARLO) && !(I2Cx->CR1 & I2C_CR1_STOP)) // If we dont have an ARLO error, ensure sending of a stop
        {
            if (I2Cx->CR1 & I2C_CR1_START)                                // We are currently trying to send a start, this is very bad as start,stop will hang the peripheral
            {
                while (I2Cx->CR1 & I2C_CR1_START);                        // Wait for any start to finish sending
                I2C_GenerateSTOP(I2Cx, ENABLE);                           // Send stop to finalise bus transaction
                while (I2Cx->CR1 & I2C_CR1_STOP);                         // Wait for stop to finish sending
                i2cInit(I2Cx);                                            // Reset and configure the hardware
            } else
            {
                I2C_GenerateSTOP(I2Cx, ENABLE);                           // Stop to free up the bus
                I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, DISABLE);     // Disable EVT and ERR interrupts while bus inactive
            }
        }
    }

    I2Cx->SR1 &= ~(I2C_SR1_OVR  |
                   I2C_SR1_AF   |
                   I2C_SR1_ARLO |
                   I2C_SR1_BERR );                                        // Reset all the error bits to clear the interrupt

    busy = 0;
}
Ejemplo n.º 12
0
void HardwareI2C::begin()
{
    /* set as master */
    if (this->i2c_d == _I2C1) afio_remap(AFIO_MAPR_I2C1_REMAP);
    i2cInit(this->i2c_d, I2C_400KHz_SPEED);
    delay(I2CDELAY);
}
Ejemplo n.º 13
0
static void i2c_er_handler(I2CDevice device) {

    I2C_TypeDef *I2Cx;
    I2Cx = i2cHardwareMap[device].dev;

    i2cState_t *state;
    state = &(i2cState[device]);

    // Read the I2C1 status register
    volatile uint32_t SR1Register = I2Cx->SR1;

    if (SR1Register & 0x0F00)                                           // an error
        state->error = true;

    // If AF, BERR or ARLO, abandon the current job and commence new if there are jobs
    if (SR1Register & 0x0700) {
        (void)I2Cx->SR2;                                                        // read second status register to clear ADDR if it is set (note that BTF will not be set after a NACK)
        I2C_ITConfig(I2Cx, I2C_IT_BUF, DISABLE);                                // disable the RXNE/TXE interrupt - prevent the ISR tailchaining onto the ER (hopefully)
        if (!(SR1Register & I2C_SR1_ARLO) && !(I2Cx->CR1 & I2C_CR1_STOP)) {     // if we dont have an ARLO error, ensure sending of a stop
            if (I2Cx->CR1 & I2C_CR1_START) {                                    // We are currently trying to send a start, this is very bad as start, stop will hang the peripheral
                while (I2Cx->CR1 & I2C_CR1_START) {; }                         // wait for any start to finish sending
                I2C_GenerateSTOP(I2Cx, ENABLE);                                 // send stop to finalise bus transaction
                while (I2Cx->CR1 & I2C_CR1_STOP) {; }                          // wait for stop to finish sending
                i2cInit(device);                                                // reset and configure the hardware
            }
            else {
                I2C_GenerateSTOP(I2Cx, ENABLE);                                 // stop to free up the bus
                I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, DISABLE);           // Disable EVT and ERR interrupts while bus inactive
            }
        }
    }
    I2Cx->SR1 &= ~0x0F00;                                                       // reset all the error bits to clear the interrupt
    state->busy = 0;
}
Ejemplo n.º 14
0
ublox5Error_e ublox5Init(void)
{
    unsigned char dat;
    int ix;
    ublox5Error_e response_error= ublox5Error_OK;
    // Initialise I2C
    if (i2cInit(I2CMODE_MASTER) == FALSE)
    {
      return ublox5Error_I2CINIT;    /* Fatal error */
    }

    //Init the GPS structure so it is obvious if we don't have a lock
    gps_gga.fix = 0;
    gps_gga.lat = 99;
    gps_gga.lon = 99;
    gps_gga.alt = 99;
    gps_gga.sat = 99;
    gps_gga.utc = 99;
    gps_gga.latitude = 99.0;
    gps_gga.longitude = 99.0;
    gps_gga.altitude = 99.0;
    gps_gga.newdata = 0;

    if (response_error == ublox5Error_OK)
    {
		gps_init = 1;
	} else {
		gps_init = 0;
    }

    return response_error;
}
Ejemplo n.º 15
0
Archivo: i2c_ctrl.c Proyecto: z80/IPM
void initI2c( void )
{
    // Address pins
    palSetPadMode( ADDR_PORT, ADDR_0_PIN, PAL_MODE_INPUT );
    palSetPadMode( ADDR_PORT, ADDR_1_PIN, PAL_MODE_INPUT );
    palSetPadMode( ADDR_PORT, ADDR_2_PIN, PAL_MODE_INPUT );
    palSetPadMode( GPIOB, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN );
    palSetPadMode( GPIOB, 7, PAL_MODE_STM32_ALTERNATE_OPENDRAIN );
    chThdSleepMilliseconds( 100 );

    i2cInit();
    //chThdSleepMilliseconds( 100 );
    i2cStart( &I2CD1, &i2cfg1 );
    //chThdSleepMilliseconds( 200 );

    // Initial values for IOs.
    int16_t i;
    for ( i=0; i<I2C_SLAVES_CNT; i++ )
    {
        outs[i]     = 0;
        pendOuts[i] = 0;
        ins[i]      = 0;
    }

    // Initializing mutex.
    chMtxInit( &mutex );
    // Creating thread.
    chThdCreateStatic( waI2c, sizeof(waI2c), NORMALPRIO, i2cThread, NULL );
}
Ejemplo n.º 16
0
static bool i2cHandleHardwareFailure(I2CDevice device)
{
    i2cErrorCount++;
    // reinit peripheral + clock out garbage
    i2cInit(device);
    return false;
}
Ejemplo n.º 17
0
static bool i2cHandleHardwareFailure(void)
{
    i2cErrorCount++;
    // reinit peripheral + clock out garbage
    i2cInit(I2Cx_index);
    return false;
}
error_t pn532_bus_HWInit(void)
{
  #ifdef PN532_DEBUGMODE
  PN532_DEBUG("Initialising I2C%s", CFG_PRINTF_NEWLINE);
  #endif
  i2cInit(I2CMASTER);

  // Set reset pin as output and reset device
  GPIOSetDir(CFG_PN532_RSTPD_PORT, CFG_PN532_RSTPD_PIN, 1);
  #ifdef PN532_DEBUGMODE
  PN532_DEBUG("Resetting the PN532%s", CFG_PRINTF_NEWLINE);
  #endif
  LPC_GPIO->CLR[CFG_PN532_RSTPD_PORT] = (1 << CFG_PN532_RSTPD_PIN);
  systickDelay(400);
  LPC_GPIO->SET[CFG_PN532_RSTPD_PORT] = (1 << CFG_PN532_RSTPD_PIN);

  // Wait for the PN532 to finish booting
  systickDelay(100);

  // Ping the I2C device first to see if it exists!
  if (i2cCheckAddress(PN532_I2C_ADDRESS) == false)
  {
    #ifdef PN532_DEBUGMODE
    PN532_DEBUG("Can't find PN532 on the I2C bus%s", CFG_PRINTF_NEWLINE);
    #endif
    return ERROR_I2C_DEVICENOTFOUND;
  }

  // Set IRQ pin to input
  GPIOSetDir(CFG_PN532_I2C_IRQPORT, CFG_PN532_I2C_IRQPIN, 0);

  return ERROR_NONE;
}
Ejemplo n.º 19
0
static void i2c_er_handler(void)
{
    volatile uint32_t SR1Register, SR2Register;
    /* Read the I2C1 status register */
    SR1Register = I2Cx->SR1;
    if (SR1Register & 0x0F00) { //an error
        error = true;
        // I2C1error.error = ((SR1Register & 0x0F00) >> 8);        //save error
        // I2C1error.job = job;    //the task
    }
    /* If AF, BERR or ARLO, abandon the current job and commence new if there are jobs */
    if (SR1Register & 0x0700) {
        SR2Register = I2Cx->SR2;        //read second status register to clear ADDR if it is set (note that BTF will not be set after a NACK)
	SR2Register = SR2Register;
        I2C_ITConfig(I2Cx, I2C_IT_BUF, DISABLE);        //disable the RXNE/TXE interrupt - prevent the ISR tailchaining onto the ER (hopefully)
        if (!(SR1Register & 0x0200) && !(I2Cx->CR1 & 0x0200)) {  //if we dont have an ARLO error, ensure sending of a stop
            if (I2Cx->CR1 & 0x0100) {   //We are currently trying to send a start, this is very bad as start,stop will hang the peripheral
                while (I2Cx->CR1 & 0x0100);     //wait for any start to finish sending
                I2C_GenerateSTOP(I2Cx, ENABLE); //send stop to finalise bus transaction
                while (I2Cx->CR1 & 0x0200);     //wait for stop to finish sending
                i2cInit(I2Cx);   //reset and configure the hardware
            } else {
                I2C_GenerateSTOP(I2Cx, ENABLE); //stop to free up the bus
                I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, DISABLE);   //Disable EVT and ERR interrupts while bus inactive
            }
        }
    }
    I2Cx->SR1 &= ~0x0F00;       //reset all the error bits to clear the interrupt
    busy = 0;
}
Ejemplo n.º 20
0
error_t tcs34725Init(void)
{
  uint8_t id = 0;

  /* Initialise I2C */
  i2cInit(I2CMASTER);

  /* Ping the I2C device first to see if it exists! */
  ASSERT(i2cCheckAddress(TCS34725_ADDRESS), ERROR_I2C_DEVICENOTFOUND);

  /* Make sure we have the right IC (0x44 = TCS34725 and TCS34721) */
  ASSERT_STATUS(tcs34725Read8(TCS34725_ID, &id));
  ASSERT(id == 0x44, ERROR_DEVICENOTINITIALISED);

  /* Enable the device */
  ASSERT_STATUS(tcs34725Enable());

  /* Ready to go ... set the initialised flag */
  _tcs34725Initialised = true;

  /* This needs to take place after the initialisation flag! */
  ASSERT_STATUS(tcs34725SetIntegrationTime(TCS34725_INTEGRATIONTIME_2_4MS));
  ASSERT_STATUS(tcs34725SetGain(TCS34725_GAIN_60X));

  return ERROR_NONE;
}
Ejemplo n.º 21
0
void setup() {
    configPins();
    initDisplay();
    detectInputMode();
    menuInit();
    i2cInit();
}
Ejemplo n.º 22
0
bool i2cRead(uint8_t addr_, uint8_t reg_, uint8_t len, uint8_t* buf)
{
    uint32_t timeout = I2C_DEFAULT_TIMEOUT;

    addr = addr_ << 1;
    reg = reg_;
    writing = 0;
    reading = 1;
    read_p = buf;
    write_p = buf;
    bytes = len;
    busy = 1;
    error = false;

    if (!(I2Cx->CR2 & I2C_IT_EVT)) {        //if we are restarting the driver
        if (!(I2Cx->CR1 & 0x0100)) {        // ensure sending a start
            while (I2Cx->CR1 & 0x0200) { ; }               //wait for any stop to finish sending
            I2C_GenerateSTART(I2Cx, ENABLE);        //send the start for the new job
        }
        I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, ENABLE);        //allow the interrupts to fire off again
    }

    while (busy && --timeout > 0);
    if (timeout == 0) {
        i2cErrorCount++;
        // reinit peripheral + clock out garbage
        i2cInit(I2Cx);
        return false;
    }

    return !error;
}
Ejemplo n.º 23
0
void systemInit(bool overclock)
{

#ifdef STM32F303xC
    // start fpu
    SCB->CPACR = (0x3 << (10*2)) | (0x3 << (11*2));
#endif

#ifdef STM32F303xC
    SetSysClock();
#endif
#ifdef STM32F10X_MD
    // Configure the System clock frequency, HCLK, PCLK2 and PCLK1 prescalers
    // Configure the Flash Latency cycles and enable prefetch buffer
    SetSysClock(overclock);
#endif

    // Configure NVIC preempt/priority groups
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

#ifdef STM32F10X_MD
    // Turn on clocks for stuff we use
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
#endif

    RCC_ClearFlag();


    enableGPIOPowerUsageAndNoiseReductions();


#ifdef STM32F10X_MD
    // Turn off JTAG port 'cause we're using the GPIO for leds
#define AFIO_MAPR_SWJ_CFG_NO_JTAG_SW            (0x2 << 24)
    AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_NO_JTAG_SW;
#endif

    ledInit();
    beeperInit();

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

#ifdef CC3D
    spiInit(SPI1);
    spiInit(SPI2);
#endif

#ifndef CC3D
    // Configure the rest of the stuff
    i2cInit(I2C2);
#endif

    // sleep for 100ms
    delay(100);
}
Ejemplo n.º 24
0
/**
 * @brief   HAL initialization.
 * @details This function invokes the low level initialization code then
 *          initializes all the drivers enabled in the HAL. Finally the
 *          board-specific initialization is performed by invoking
 *          @p boardInit() (usually defined in @p board.c).
 *
 * @init
 */
void halInit(void) {

  hal_lld_init();

#if HAL_USE_TM || defined(__DOXYGEN__)
  tmInit();
#endif
#if HAL_USE_PAL || defined(__DOXYGEN__)
  palInit(&pal_default_config);
#endif
#if HAL_USE_ADC || defined(__DOXYGEN__)
  adcInit();
#endif
#if HAL_USE_CAN || defined(__DOXYGEN__)
  canInit();
#endif
#if HAL_USE_EXT || defined(__DOXYGEN__)
  extInit();
#endif
#if HAL_USE_GPT || defined(__DOXYGEN__)
  gptInit();
#endif
#if HAL_USE_I2C || defined(__DOXYGEN__)
  i2cInit();
#endif
#if HAL_USE_ICU || defined(__DOXYGEN__)
  icuInit();
#endif
#if HAL_USE_MAC || defined(__DOXYGEN__)
  macInit();
#endif
#if HAL_USE_PWM || defined(__DOXYGEN__)
  pwmInit();
#endif
#if HAL_USE_SERIAL || defined(__DOXYGEN__)
  sdInit();
#endif
#if HAL_USE_SDC || defined(__DOXYGEN__)
  //KL All in Kl_sdc sdcInit();
#endif
#if HAL_USE_SPI || defined(__DOXYGEN__)
  spiInit();
#endif
#if HAL_USE_UART || defined(__DOXYGEN__)
  uartInit();
#endif
#if HAL_USE_USB || defined(__DOXYGEN__)
  usbInit();
#endif
#if HAL_USE_MMC_SPI || defined(__DOXYGEN__)
  mmcInit();
#endif
#if HAL_USE_SERIAL_USB || defined(__DOXYGEN__)
  sduInit();
#endif
#if HAL_USE_RTC || defined(__DOXYGEN__)
  rtcInit();
#endif
}
Ejemplo n.º 25
0
void initI2Cmodule(void) {
	print("Starting I2C module\r\n");
	i2cInit();
	i2cStart(&I2CD1, &i2cfg);

	efiSetPadMode("I2C clock", EFI_I2C_SCL_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_I2C_AF) | PAL_STM32_OTYPE_OPENDRAIN);
	efiSetPadMode("I2C data", EFI_I2C_SDA_BRAIN_PIN, PAL_MODE_ALTERNATE(EFI_I2C_AF) | PAL_STM32_OTYPE_OPENDRAIN);
}
Ejemplo n.º 26
0
void spyglassInit(void)
{
	i2cInit();
	i2cSetBitrate(100);
	PcfCtrlData = (SPYGLASS_LED0 | SPYGLASS_LED1 | SPYGLASS_BEEPER);
	spyglassSetLeds(0);
	spyglassSetBeeper(0);
}
Ejemplo n.º 27
0
void boardInit(void)
{
    SIM_SCGC5 |= 0x00000400; //enable Port B clock
    SIM_SCGC5 |= 0x00000200; //enable Port A clock
    SIM_SCGC5 |= 0x00001000; //enable Port D clock

    PORTB_PCR19 |= (uint32_t)0x00000100; //Configure portB19 as GPIO (GREEN)
    GPIOB_PDDR |= (uint32_t)0x00080000; //Configure portB19 as output

    PORTA_PCR12 |= (uint32_t)0x000A0102; //Configure portA12 as GPIO with falling edge interrupt and pullup enabled.
    GPIOA_PDDR &= ~(uint32_t)(1<<12); //Configure portA12 as input.

    PORTB_PCR18 |= (uint32_t)0x00000100; //Configure portB18 as GPIO (RED)
    GPIOB_PSOR |= (uint32_t)0x00040000;
    GPIOB_PDDR |= (uint32_t)0x00040000; //Configure portB18 as output

    PORTD_PCR1 |= (uint32_t)0x00000100; //Configure portD1 as GPIO (BLUE)
    FGPIOD_PSOR |= (uint32_t)0x00000002;
    FGPIOD_PDDR |= (uint32_t)0x00000002; //Configure portD1 as output

    //SIM_SCGC6 |= (uint8_t) 0x00800000; // Enable PIT clock

    SIM_SOPT2 |= 0x01000000; // Set TPM to use the MCGFLLCLK as a clock source
    // MCGFLLCLK is either 24MHz or 23 986 176Hz
    SIM_SCGC6 |= 0x01000000; // Enable TPM0 clock

    uart0Config();
    uart0Enable();

    llwuConfigure();
    vllsEnable();
    vllsConfigure(1);

    PMC_REGSC = 0x08;

    systickConfigure();

    interruptSetPriority(30,0); //Port A ISR
    interruptEnable(30);

    interruptSetPriority(7,0); // Configure LLWU interrupt as highest priority.
    interruptEnable(7); //Enable LLWU interrupt.

    systickEnable();

    rtcInit();
    rtcStart();

    interruptSetPriority(21,0); // Configure RTC Seconds interrupt as highest priority.
    interruptEnable(21); //Enable RTC Seconds interrupt.

    i2cInit();
    interruptSetPriority(9,3); // Configure I2C interrupt as Lowest priority.
    interruptEnable(9); //Enable I2C interrupt.

    interruptSetPriority(22,3); // Configure PIT interrupt as Lowest priority.
    interruptEnable(9); //Enable PIT interrupt.
}
Ejemplo n.º 28
0
void systemInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    uint8_t i;

    gpio_config_t gpio_cfg[] = {
        { LED0_GPIO, LED0_PIN, GPIO_Mode_Out_PP }, // PB3 (LED)
        { LED1_GPIO, LED1_PIN, GPIO_Mode_Out_PP }, // PB4 (LED)
#ifndef FY90Q
        { BEEP_GPIO, BEEP_PIN, GPIO_Mode_Out_OD }, // PA12 (Buzzer)
#endif
    };
    uint8_t gpio_count = sizeof(gpio_cfg) / sizeof(gpio_cfg[0]);

    // Turn on clocks for stuff we use
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4 | RCC_APB1Periph_I2C2, ENABLE);
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_TIM1 | RCC_APB2Periph_ADC1 | RCC_APB2Periph_USART1, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
    RCC_ClearFlag();

    // Make all GPIO in by default to save power and reduce noise
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Init(GPIOC, &GPIO_InitStructure);

    // Turn off JTAG port 'cause we're using the GPIO for leds
    GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);

    // Configure gpio
    for (i = 0; i < gpio_count; i++) {
        GPIO_InitStructure.GPIO_Pin = gpio_cfg[i].pin;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = gpio_cfg[i].mode;
        GPIO_Init(gpio_cfg[i].gpio, &GPIO_InitStructure);
    }

    LED0_OFF;
    LED1_OFF;
    BEEP_OFF;

    // Init cycle counter
    cycleCounterInit();

    // SysTick
    SysTick_Config(SystemCoreClock / 1000);

    // Configure the rest of the stuff
    adcInit();
#ifndef FY90Q
    i2cInit(I2C2);
#endif

    // sleep for 100ms
    delay(100);
}
Ejemplo n.º 29
0
void rtcInit(void)
{
	i2cInit();
	i2cStart();
	i2cWrite(0xD0); // Address the RTC to write
	i2cWrite(0x07);
	i2cWrite(0x00);
	i2cStop();
}
Ejemplo n.º 30
0
void Daisy23::begin() {
	DDRC |= 0b00010011;
	PORTC = 0b00110000;  // Pull-ups on I2C Bus
	i2cInit();
	mpr_config();
	mpr_lcd_init();	
	delay(100);
	mpr_config();
}