Exemple #1
0
void xhide(void)
{
	spi_transfer(low_byte(400));
  spi_transfer(high_byte(400));
  spi_transfer(low_byte(400));
  spi_transfer(high_byte(400));
  //spr++;
}
Exemple #2
0
void __start(unsigned int addr) // start an SPI transaction to addr
{
	rFIO0CLR |= 1<<16;  //select slave
	
	spi_transfer(high_byte(addr));
	spi_transfer(low_byte(addr));
}
Exemple #3
0
void EEPROM_ByteWrite(u16 Address, u08 Data)
// Description:
//   Byte Write Operation. The communication via the I2C bus with an EEPROM
//   (2465) is realized. A data byte is written into a user defined address.
{

	/* i2c por SW */
#if (defined I2C_SW &&  I2C_SW == 1)
	sw_i2c_start();							// Send start signal
	sw_i2c_write(EEPROMAddress & 0b11111110);// Send identifier I2C address     0xA0 = 10100000b
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char)(high_byte(Address)));// Send address to EEPROM (high byte address)
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) Address);// Send address to EEPROM  (low byte address) 
	delay_time(I2C_DELAY);
	sw_i2c_write(Data);// Send low byte to EEPROM  (data to write)
	delay_time(I2C_DELAY);// Delay a period of time to write   
	sw_i2c_stop();	   // Send I2C Stop Transfer
	delay_time(20);	   // Delay a period of time to write
	DelayTask(WRITE_CYCLE_TIME);
#else
	/* i2c por HW */

	IIC_transmite(EEPROMAddress, Address, &Data);

#endif
}
Exemple #4
0
/*---------------------------------------------------------------------------*/
u08 EEPROM_RandomRead(u16 Address)
// Description:
//   Random Read Operation. Data is read from the EEPROM. The EEPROM
//   address is defined with the parameter Address.
{

	char data_in;
#if (defined I2C_SW &&  I2C_SW == 1)
	sw_i2c_start();							// Send start signal

	sw_i2c_write(EEPROMAddress);// Send identifer I2C address  (10100000b)
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) (high_byte(Address)));// Send address to EEPROM
	delay_time(I2C_DELAY);
	sw_i2c_write((unsigned char) Address);// Send address to EEPROM
	delay_time(I2C_DELAY);
	sw_i2c_start();// Send I2C Start Transfer
	sw_i2c_write(EEPROMAddress + 1);// Send identifer I2C address  (10100001b)
	delay_time(I2C_DELAY);
	data_in = sw_i2c_read(0);// Read byte
	sw_i2c_stop();			 // Send I2C Stop Transfer
#else

	/* Dummy write: Transmite NULL depois gera um sinal de start repeated */
	IIC_transmite(EEPROMAddress, Address, NULL);
	IIC_recebe(EEPROMAddress, &data_in);
	

#endif
	return data_in;

}
Exemple #5
0
void wr16(unsigned int addr, unsigned int v)
{
	  __wstart(addr);
  spi_transfer(low_byte(v));
  spi_transfer(high_byte(v));
  __end();
	
}
//------------------------------------------------------------------------------
// Procedure:	write_byte
// Inputs:		data out, address
// Outputs:		none
// Description:	Writes a byte to the EEPROM given the address 
//------------------------------------------------------------------------------
void write_byte (unsigned char data_out, unsigned int address)
{
  	send_slave_address_I2C(0xA0); 			// Send I2C Start Transfer
       					         			// Send identifier I2C address
   	write_byte_I2C(high_byte(address)); 	// Send address to EEPROM
   	write_byte_I2C((unsigned char)address); // Send address to EEPROM
   	write_byte_I2C(data_out);          		// Send low byte to EEPROM
   	stop_I2C();                   			// Send I2C Stop Transfer
   	delay_time(DELAY_WRITE);       			// Delay a period of time to write
}
Exemple #7
0
static void w5200_write_register(uint16_t addr, uint8_t data) {
    
    spi_cs_low();

    spi_transfer(high_byte(addr));
    spi_transfer(low_byte(addr));
    spi_transfer(0x80);
    spi_transfer(0x01);
    spi_transfer(data);
    
    spi_cs_high();

}
//------------------------------------------------------------------------------
// Procedure:	read_byte
// Inputs:		address
// Outputs:		output byte
// Description:	Reads a byte from the EEPROM given the address 
//------------------------------------------------------------------------------
unsigned char read_byte (unsigned int address)
{
   	unsigned char data_in;

  	send_slave_address_I2C(0xA0); 			// Send I2C Start Transfer
   					              			// Send identifer I2C address
   	write_byte_I2C(high_byte(address));   	// Send address to EEPROM
   	write_byte_I2C((unsigned char)address); // Send address to EEPROM
   	restart_I2C(0xA1);         				// Send identifer I2C address
   	read_byte_I2C(&data_in);     			// Read byte
   	stop_I2C();                   			// Send I2C Stop Transfer

   	return data_in;                 
}
Exemple #9
0
/* Private register IO functions */
static uint8_t w5200_read_register(uint16_t addr){
	
	uint8_t data;

	spi_cs_low();

	spi_transfer(high_byte(addr));
	spi_transfer(low_byte(addr));
	spi_transfer(0x00);
	spi_transfer(0x01);
	data = spi_transfer(0);

	spi_cs_high();
	
	return data;
}
Exemple #10
0
Dynamixel::CommStatus Dynamixel::write_word(unsigned char id, unsigned char address, int value) {
    const unsigned char parameters[3] = {address, low_byte(value), high_byte(value)};
    return send_instruction_read_status(id, 0x03, parameters, 3);
}