Пример #1
0
/*-----------------------------------------------------------------------------
 *      I2C_Recovery:   Recovery procedure for I2C lines when irregular 
 *                      communication interrupt occures.
 *
 * Return:     0 on success, nonzero on error
 *----------------------------------------------------------------------------*/
uint32_t I2C_Recovery (uint32_t err) {
  uint32_t i;
#if 1
  GPIOB->AFR[1]  &= ~0x000000FF;        /* Set SDA and SCL as GPIO            */
  I2C1->CR1 |= I2C_CR1_SWRST;           /* Put I2C peripheral in reset mode   */

  io_dir (IO_SDA | IO_SCL, IO_OUT);     /* SDA and SCL pins are outputs       */
  io_pin (IO_SDA | IO_SCL, IO_HI);      /* Pull both lines high               */
  Wait();  
  io_pin (IO_SCL, IO_LOW);              /* Generate start ccondition          */
  io_pin (IO_SDA, IO_HI);               /* Pull SDA high                      */
  for (i = 0; i < 9; i++) {
    if (io_state (IO_SDA) == IO_HI) break;  /* Break if SDA released by slave */
    io_pin (IO_SCL, IO_HI);             /* Clock high                         */
    Wait();
    io_pin (IO_SCL, IO_LOW);            /* Clock low                          */
    Wait();    
  }
  /* Send stop */
  io_pin (IO_SDA, IO_LOW);              /* Pull SDA low                       */
  io_pin (IO_SCL, IO_HI);               /* Pull SCL high                      */
  Wait();
  io_pin (IO_SDA, IO_HI);               /* Pull SDA high == stop condition    */

  I2C1->CR1 &= ~I2C_CR1_SWRST;          /* Dereset I2C peripheral             */
  return (I2C_Init());                  /* Reinit I2C peripheral              */
#else
  return (1);
#endif
}
Пример #2
0
void gpio_input(unsigned char idx) //14may15 experiment
{
	uint32_t ioFlags;
	unsigned char ioPin;
		
	ioPin = io_pin(idx);
		
	ioport_set_pin_dir(ioPin, IOPORT_DIR_INPUT);


}
Пример #3
0
void release_the_bus(unsigned char idx)
{
	unsigned char ioPin;
	int32_t ioFlags;
	
	ioPin = io_pin(idx);
	
	ioport_set_pin_dir(ioPin, IOPORT_DIR_INPUT);
	

}
Пример #4
0
void drive_DQ_low(unsigned char idx)
{
	unsigned char ioPin;
	int32_t ioFlags;
	
	ioPin = io_pin(idx);
	
	ioport_set_pin_dir(ioPin, IOPORT_DIR_OUTPUT);
	ioport_set_pin_level(ioPin, IOPORT_PIN_LEVEL_LOW);

}
Пример #5
0
void drive_DQ_low_and_release_the_bus(unsigned char idx)
{
	unsigned char ioPin;
	int32_t ioFlagsOutput, ioFlagsInput;
	
	ioPin = io_pin(idx);
	
	ioport_set_pin_dir(ioPin, IOPORT_DIR_OUTPUT);
	ioport_set_pin_level(ioPin, IOPORT_PIN_LEVEL_LOW);

	udelay(A);	//tW1L 5-15us

	ioport_set_pin_dir(ioPin, IOPORT_DIR_INPUT);
	
}
Пример #6
0
unsigned char sample_line(unsigned char idx)
{
//14may15 experiment		uint32_t ioFlags;
		unsigned char retVal, ioPin;
		
		ioPin = io_pin(idx);
		
//14may15 experiment		ioFlags = (GPIO_DIR_INPUT);
//14may15 experiment		gpio_configure_pin(ioPin, ioFlags);

		retVal = ioport_get_pin_level(ioPin);

//14may15 experiment		ioFlags = (GPIO_DIR_OUTPUT);
//14may15 experiment		gpio_configure_pin(ioPin, ioFlags);

		return retVal;
}