예제 #1
0
static int WriteStI2CRegister (I2C_M_SETUP_Type* setup, uint8_t register_address, uint8_t value)
{
    uint8_t transmit_buffer[2];
    int     result;
    uint8_t receive_buffer;

    transmit_buffer[0] = register_address;
    transmit_buffer[1] = value;

    setup->tx_data   = transmit_buffer;
    setup->tx_length = 2;
    setup->rx_data   = &receive_buffer;
    setup->rx_length = 0;

    result = I2C_MasterTransferData(LPC_I2C0, setup, I2C_TRANSFER_POLLING);
    if(result == ERROR)
        return 1;

    setup->tx_length = 1;
    setup->rx_length = 1;

    result = I2C_MasterTransferData(LPC_I2C0, setup, I2C_TRANSFER_POLLING);
    if(result == ERROR || receive_buffer != value)
        return 1;

    return 0;
}
/******************************************************************************
 * Public Functions
 *****************************************************************************/
void SetPWM(uint8_t brightness)
{
    /* Transmit setup */
    I2C_M_SETUP_Type txsetup;
    uint8_t i2c_buf[2];
    
    txsetup.sl_addr7bit = I2C_PCA9532_ADDR;
    txsetup.tx_data = i2c_buf;
    txsetup.tx_length = 2;
    txsetup.rx_data = NULL;
    txsetup.rx_length = 0;
    txsetup.retransmissions_max = 3;

    i2c_buf[0] = PSC0;  // frequency setting
    i2c_buf[1] = 0;       // max
    if (I2C_MasterTransferData((en_I2C_unitId)I2CDEV, &txsetup, I2C_TRANSFER_POLLING) != SUCCESS){
        return;
    }
    
    i2c_buf[0] = PWM0;  // duty-cycle
    i2c_buf[1] = (100-brightness)*PCA9532_PWM_FACTOR / PERCENT_FACTOR;      // brightness setting
    if (I2C_MasterTransferData((en_I2C_unitId)I2CDEV, &txsetup, I2C_TRANSFER_POLLING) != SUCCESS){
        return;
    }
    
    i2c_buf[0] = LSn(LCD_BL_CONSTRAST_PIN_NUM); //source of the BL pin 
    i2c_buf[1] = LCD_OUT_PWM0<<(BITn(LCD_BL_CONSTRAST_PIN_NUM));   // use PWM0 output
    if (I2C_MasterTransferData((en_I2C_unitId)I2CDEV, &txsetup, I2C_TRANSFER_POLLING) != SUCCESS){
        return;
    }
}
예제 #3
0
파일: BH1750.c 프로젝트: vpcola/LPC1769_NYP
void Init_BH1750()
{
	// Power on BH1750
	unsigned char data[2];
	data[0] = BH1750_POWER_ON;

	I2C_M_SETUP_Type I2CRxTx;

	I2CRxTx.sl_addr7bit = BH1750_I2CADDR;
	I2CRxTx.tx_data = &data[0];
	I2CRxTx.tx_length = 1;
	I2CRxTx.rx_data = NULL;
	I2CRxTx.rx_length = 0;
	I2CRxTx.retransmissions_max = 3;
	I2C_MasterTransferData(LPC_I2C2, &I2CRxTx, I2C_TRANSFER_POLLING);

	// Start continous BH1750_CONTINUOUS_HIGH_RES_MODE
	data[0] = BH1750_CONTINUOUS_HIGH_RES_MODE;

	I2CRxTx.sl_addr7bit = BH1750_I2CADDR;
	I2CRxTx.tx_data = &data[0];
	I2CRxTx.tx_length = 1;
	I2CRxTx.rx_data = NULL;
	I2CRxTx.rx_length = 0;
	I2CRxTx.retransmissions_max = 3;
	I2C_MasterTransferData(LPC_I2C2, &I2CRxTx, I2C_TRANSFER_POLLING);

}
void LEDs_Init(void)
{
	I2C_M_SETUP_Type transferMCfg;
	uint8_t sendbuf[4]; //,receivebuf,tem;

	/* Initiate I2C */
	I2C_Init(LPC_I2C, 100000);
	I2C_Cmd(LPC_I2C, ENABLE);

	/* Configure PCA9502 */
	sendbuf[0] = PCA9502_REG_ADDR(PCA9502_REG_IODIR);
	sendbuf[1] = 0x0F;						/* IO[7:4]=input IO[3:0]=output */
	transferMCfg.sl_addr7bit = I2CDEV_PCA9502_ADDR;
	transferMCfg.tx_data = sendbuf ;
	transferMCfg.tx_length = 2;
	transferMCfg.rx_data = NULL;
	transferMCfg.rx_length = 0;
	transferMCfg.retransmissions_max = 3;
	I2C_MasterTransferData(LPC_I2C, &transferMCfg, I2C_TRANSFER_POLLING);

	sendbuf[0] = PCA9502_REG_ADDR(PCA9502_REG_IOSTATE);
	sendbuf[1] = 0x0F;						/* all output low */
	transferMCfg.sl_addr7bit = I2CDEV_PCA9502_ADDR;
	transferMCfg.tx_data = sendbuf ;
	transferMCfg.tx_length = 2;
	transferMCfg.rx_data = NULL;
	transferMCfg.rx_length = 0;
	transferMCfg.retransmissions_max = 3;
	I2C_MasterTransferData(LPC_I2C, &transferMCfg, I2C_TRANSFER_POLLING);
}
예제 #5
0
void InitHMC5883L(void)
{
	/* Setup the sensor */
	uint8_t send[2];
	uint8_t receive;
	I2C_MASTER_SETUP_Type Setup;

	Setup.Slave_Address_7bit = HMC5883L_ADDRESS;
	Setup.TX_Data = send;
	Setup.RX_Data = &receive;
	Setup.Retransmissions_Max = 5;
	Setup.Callback = NULL;
	Setup.TX_Length = 2;
	Setup.RX_Length = 0;

	/* Set averaging, update rate and bias */
	send[0] = HMC5883L_RA_CONFIG_A;
	send[1] = 0b01111000; /* 8 averages, 75Hz, normal mode */
	I2C_MasterTransferData(I2C2, &Setup, I2C_TRANSFER_POLLING);

	/* Set the gain */
	send[0] = HMC5883L_RA_CONFIG_B;
	send[1] = 0b00100000; /* Default gain of 1090 LSB/Gauss*/
	I2C_MasterTransferData(I2C2, &Setup, I2C_TRANSFER_POLLING);

    /* Set the mode, continous or single */
	send[0] = HMC5883L_RA_MODE;
	send[1] = 0; /* Continuous measurement mode */
	I2C_MasterTransferData(I2C2, &Setup, I2C_TRANSFER_POLLING);
}
예제 #6
0
void init_display(int i2c_port){
    /*while (read_busy_flag_display(i2c_port) == 1){
        // empty while just to check the flag
    }*/
    sleep(10000);
    uint8_t write[11] = {0x00,0x34,0x0c,0x06,0x35,0x04,0x10,0x42,0x9f,0x34,0x02};
    I2C_M_SETUP_Type TransferCfg;
    TransferCfg = setup_TransferCfg(TransferCfg, i2c_port, write, 11, NULL, 0);
    I2C_MasterTransferData(usedi2c, &TransferCfg, I2C_TRANSFER_POLLING);
    sleep(1000);
    uint8_t write2[2] = {0x00, 0x01};
    TransferCfg = setup_TransferCfg(TransferCfg, i2c_port, write2, 2, NULL, 0);
    I2C_MasterTransferData(usedi2c, &TransferCfg, I2C_TRANSFER_POLLING);
    sleep(2000);
    clear_display(i2c_port);
}
예제 #7
0
void vParTestInitialise( void )
{
unsigned char ucBuffer[ 2 ];
I2C_M_SETUP_Type xI2CMessage;

	/* The LEDs are on an I2C IO expander.  Initialise the I2C interface. */
	I2C_Init( LPC_I2C0, 300000 );
	I2C_Cmd( LPC_I2C0, ENABLE );

	/* GPIO0-GPIO2 to output. */
	ucBuffer[ 0 ] = partstIO_DIR_COMMAND;
	ucBuffer[ 1 ] = 0x0f;
	xI2CMessage.sl_addr7bit = partstSLAVE_ADDRESS;
	xI2CMessage.tx_data = ucBuffer ;
	xI2CMessage.tx_length = sizeof( ucBuffer );
	xI2CMessage.rx_data = NULL;
	xI2CMessage.rx_length = 0;
	xI2CMessage.retransmissions_max = 3;
	I2C_MasterTransferData( LPC_I2C0, &xI2CMessage, I2C_TRANSFER_POLLING );

	/* Create the mutex used to guard access to the I2C bus. */
	xI2CCommandQueue = xQueueCreate( partstLED_COMMAND_QUEUE_LENGTH, sizeof( unsigned char ) );
	configASSERT( xI2CCommandQueue );

	/* Create the I2C gatekeeper task itself. */
	xTaskCreate( prvI2CGateKeeperTask, ( signed char * ) "I2C", configMINIMAL_STACK_SIZE, ( void * ) NULL, tskIDLE_PRIORITY, NULL );
}
예제 #8
0
int _readMag(uint8_t * args)
{
    uint8_t          receive_buffer[6];
    I2C_M_SETUP_Type setup;
    unsigned int     x_value;
    unsigned int     y_value;
    unsigned int     z_value;
    Status           result;
    uint8_t          transmit_buffer;

    setup.sl_addr7bit         = MAG_I2C_SLAVE_ADDRESS;
    setup.retransmissions_max = MAX_ST_I2C_RETRANSMISSIONS;

    setup.tx_data   = &transmit_buffer;
    setup.tx_length = 1;
    setup.rx_data   = receive_buffer;
    setup.rx_length = 6;

    transmit_buffer = MAG_DATA_ADDRESS|ST_I2C_AUTOINCREMENT_ADDRESS;

    result = I2C_MasterTransferData(LPC_I2C0, &setup, I2C_TRANSFER_POLLING);
    if(result == ERROR)
        return 1;

    x_value = MagDataToUInt32(&receive_buffer[0]);
    y_value = MagDataToUInt32(&receive_buffer[2]);
    z_value = MagDataToUInt32(&receive_buffer[4]);

    sprintf((char*)str, "%x %x %x\r\n", x_value, y_value, z_value);
    writeUSBOutString(str);

    return 0;
}
예제 #9
0
void get_mac_addr(uint8_t *mac_buf) {
	PINSEL_CFG_Type PinCfg;
	I2C_M_SETUP_Type transferMCfg;

	uint8_t eeprom_addr = EEPROM_ADDR;

	/* Configure I2C0 */
	PinCfg.OpenDrain = PINSEL_PINMODE_OPENDRAIN;
	PinCfg.Pinmode = PINSEL_PINMODE_TRISTATE;
	PinCfg.Funcnum = 1;
	PinCfg.Pinnum = 27;
	PinCfg.Portnum = 0;
	PINSEL_ConfigPin(&PinCfg);
	PinCfg.Pinnum = 28;
	PINSEL_ConfigPin(&PinCfg);
	// Initialize Slave I2C peripheral
	/* Set up clock and power for I2C0 module */
	CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C0, ENABLE);
	/* As default, peripheral clock for I2C0 module
	 * is set to FCCLK / 2 */
	CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_I2C0, CLKPWR_PCLKSEL_CCLK_DIV_2);


	transferMCfg.sl_addr7bit = I2CDEV_S_ADDR;
	transferMCfg.tx_data = &eeprom_addr;
	transferMCfg.tx_length = 1;
	transferMCfg.rx_data = mac_buf;
	transferMCfg.rx_length = MAC_ADDR_SIZE;
	transferMCfg.retransmissions_max = 3;
	I2C_MasterTransferData(LPC_I2C0, &transferMCfg, I2C_TRANSFER_POLLING);

	/** deinitialize I2C0 */
	LPC_I2C0->I2CONCLR = I2C_I2CONCLR_I2ENC;
	CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C0, DISABLE);
}
예제 #10
0
/*
Pre-Reqs: setupI2C1(), setupUART()
Desc: Queries all the addresses on the I2C bus to see how many devices are connected
and their addresses
*/
void I2CSniffer(){
	uint8_t tx_dat = 0;
	uint32_t i2caddress = 0x00;
	int addrcount = 0;
	I2C_M_SETUP_Type TransferCfg;
	for(i2caddress = 0x00; i2caddress < 128; i2caddress++){
		TransferCfg.sl_addr7bit = i2caddress;
		TransferCfg.tx_data = &tx_dat;
		TransferCfg.tx_length = 1;
		TransferCfg.rx_data = NULL;
		TransferCfg.rx_length = 0;
		TransferCfg.retransmissions_max = 3;
		if(I2C_MasterTransferData(LPC_I2C1, &TransferCfg, I2C_TRANSFER_POLLING) != 0){
			//displayBits(15, 5);
			sprintf(strPtr, "\r\nAddress: %X\t", i2caddress);
			UART_SendMSG(strPtr, msg);
			addrcount++;
			SystickTimer(5);
		}else{
		 	//sprintf(msg, "\r\nFailure\t");
		 	//UART_SendMSG(strPtr, msg);
		}
		sprintf(strPtr, "\r\nTotal Addresses: %d\t", addrcount);
		UART_SendMSG(strPtr, msg);
	}
}
예제 #11
0
void write_display(int i2c_port, uint8_t address, char char_to_send){
    /*while (read_busy_flag_display(i2c_port) == 1){
        write_usb_serial_blocking("busy1\n\r", 7);
    }*/
    uint8_t writeadd[2] = {0x00, address};
    uint8_t writedata[2] = {0x40, char_to_send};
    sleep(1000);

    I2C_M_SETUP_Type TransferCfg;
    TransferCfg = setup_TransferCfg(TransferCfg, i2c_port, writeadd, 2, NULL, 0);
    I2C_MasterTransferData(usedi2c, &TransferCfg, I2C_TRANSFER_POLLING);

    /*while (read_busy_flag_display(i2c_port) == 1){
        write_usb_serial_blocking("busy2\n\r", 7);
    }*/
    sleep(1000);
    TransferCfg = setup_TransferCfg(TransferCfg, i2c_port, writedata, 2, NULL, 0);
    I2C_MasterTransferData(usedi2c, &TransferCfg, I2C_TRANSFER_POLLING);
}
예제 #12
0
/*
Pre-Reqs: setupI2C1(), setupUART()
Desc: Polls the keyboard to detect key presses.
Outputs: char key - the button that was pressed
*/
char KeypadTest(){
	uint8_t* rx_dat;
	uint32_t i2caddress = KEYADDR;
	char buttonPressed;

	uint8_t cols[4] = {0x7F, 0xBF, 0xDF, 0xEF};
	int i;
	int row = -1;
	int column = -1;
	for (i=0; i<4; ++i) {
		uint8_t key_init[1] = {cols[i]};
		uint8_t key_prsd[1] = {0x00};
		dataPtr = key_init;
		rx_dat = key_prsd;
		sendToI2C1(i2caddress, dataPtr, 1);


		I2C_M_SETUP_Type TransferCfg;
		TransferCfg.sl_addr7bit = i2caddress;
		TransferCfg.tx_data = NULL;
		TransferCfg.tx_length = 0;
		TransferCfg.rx_data = rx_dat;
		TransferCfg.rx_length = sizeof(uint8_t);

		if(I2C_MasterTransferData((LPC_I2C_TypeDef *)LPC_I2C1, &TransferCfg, I2C_TRANSFER_POLLING) != 0){
			switch (*rx_dat&0xf){
				case 0x7:
					column = 0;
					row = i;
					break;
				case 0xB:
					column = 1;
					row = i;
					break;
				case 0xD:
					column = 2;
					row = i;
					break;
				case 0xE:
					column = 3;
					row = i;
					break;
			}
		} else {
			return NULL;
		}
		//30ms Polling Delay
		// SystickTimer(30);
	}
	if (column>=0) {
		return KEYPAD[column][row];
	} else {
		return NULL;
	}
}
예제 #13
0
static int32_t sendCmd(uint8_t cmd)
{
	i2c.tx_data = &cmd;
	i2c.tx_length = 1;
	i2c.rx_data = NULL;
	i2c.rx_length = 0;

	if (I2C_MasterTransferData(I2C_DEV, &i2c, I2C_TRANSFER_POLLING) == SUCCESS)
		return 0;
	else
		return -1;
}
예제 #14
0
파일: i2c.c 프로젝트: Nanor/mbed-orchestra
int I2C_tr(uint32_t address, uint8_t* t_data, uint32_t t_length, uint8_t* r_data, uint32_t r_length)
{
	I2C_M_SETUP_Type i2c_setup;
	i2c_setup.sl_addr7bit = address;
	i2c_setup.tx_data = t_data;
	i2c_setup.tx_length = t_length;
	i2c_setup.rx_length = r_length;
	i2c_setup.rx_data = r_data;
	i2c_setup.retransmissions_max = 3;

	return(I2C_MasterTransferData(LPC_I2C1, &i2c_setup, I2C_TRANSFER_POLLING));
}
예제 #15
0
파일: i2c.c 프로젝트: Nanor/mbed-orchestra
int I2C_send(uint32_t address, uint8_t* data, uint32_t length)
{
	I2C_M_SETUP_Type i2c_setup;
	i2c_setup.sl_addr7bit = address;
	i2c_setup.tx_data = data;
	i2c_setup.tx_length = length;
	i2c_setup.rx_length = 0;
	i2c_setup.rx_data = NULL;
	i2c_setup.retransmissions_max = 3;

	return(I2C_MasterTransferData(LPC_I2C1, &i2c_setup, I2C_TRANSFER_POLLING));
}
예제 #16
0
void columnwrite(unsigned char * buf) {
                
                I2C_M_SETUP_Type SEND;

                SEND.sl_addr7bit = 33;
                SEND.tx_data = buf;
                SEND.tx_length = sizeof(unsigned char);
                SEND.rx_data = NULL;
                SEND.rx_length = 0;
                SEND.retransmissions_max = 3;

                I2C_MasterTransferData((LPC_I2C_TypeDef *) LPC_I2C1 , &SEND, I2C_TRANSFER_POLLING );
                }
예제 #17
0
void columnread(unsigned char * buf) {

                I2C_M_SETUP_Type READ;                        
                
                READ.sl_addr7bit = 33;
                READ.tx_data = NULL;
                READ.tx_length = 0;
                READ.rx_data = &buf[0];
                READ.rx_length = sizeof(unsigned char);
                READ.retransmissions_max = 3;
                              
                I2C_MasterTransferData((LPC_I2C_TypeDef *) LPC_I2C1 , &READ, I2C_TRANSFER_POLLING );
                }
예제 #18
0
파일: lm75a.c 프로젝트: Blackclaws/tinyusb
static Status I2CRead(uint32_t addr, uint8_t* buf, uint32_t len) 
{
  I2C_M_SETUP_Type i2cData;

	i2cData.sl_addr7bit = addr;
	i2cData.tx_data = NULL;
	i2cData.tx_length = 0;
	i2cData.rx_data = buf;
	i2cData.rx_length = len;
	i2cData.retransmissions_max = 3;

  return I2C_MasterTransferData(I2C_PORT, &i2cData, I2C_TRANSFER_POLLING);
}
예제 #19
0
void printchar(uint8_t * buf) {
        count += 1;
        I2C_M_SETUP_Type SEND;
        
        SEND.sl_addr7bit = 59;
        SEND.tx_data = buf;
        SEND.tx_length = sizeof(uint8_t) * 2;
        SEND.rx_data = NULL;
        SEND.rx_length = 0;
        SEND.retransmissions_max = 3;        

        I2C_MasterTransferData((LPC_I2C_TypeDef *) LPC_I2C1 , &SEND, I2C_TRANSFER_POLLING );

}
예제 #20
0
void lcdclear(void){
        
        I2C_M_SETUP_Type SEND;

        uint8_t clear[2] = {0x00 , 0x01};
        
        SEND.sl_addr7bit = 59;
        SEND.tx_data = clear;
        SEND.tx_length = sizeof(uint8_t)*2;
        SEND.rx_data = NULL;
        SEND.rx_length = 0;
        SEND.retransmissions_max = 3;

        I2C_MasterTransferData((LPC_I2C_TypeDef *) LPC_I2C1 , &SEND, I2C_TRANSFER_POLLING );
}
예제 #21
0
ErrorStatus GetHMC5883LID(uint8_t *data)
{
	static uint8_t send = HMC5883L_RA_ID_A;
	I2C_MASTER_SETUP_Type Setup;

	Setup.Slave_Address_7bit = HMC5883L_ADDRESS;
	Setup.TX_Data = &send;
	Setup.TX_Length = 1;
	Setup.RX_Data = data;
	Setup.RX_Length = 3;
	Setup.Retransmissions_Max = 0;
	Setup.Callback = NULL;

	return I2C_MasterTransferData(I2C2, &Setup, I2C_TRANSFER_POLLING);
}
void LEDs_SetAllLEDs(uint32_t LEDMask)
{
	I2C_M_SETUP_Type transferMCfg;
	uint8_t sendbuf[2];

	sendbuf[0] = PCA9502_REG_ADDR(PCA9502_REG_IOSTATE);
	sendbuf[1] = ~(uint8_t)(LEDMask & 0x0F);
	transferMCfg.sl_addr7bit = I2CDEV_PCA9502_ADDR;
	transferMCfg.tx_data = sendbuf ;
	transferMCfg.tx_length = 2;
	transferMCfg.rx_data = NULL;
	transferMCfg.rx_length = 0;
	transferMCfg.retransmissions_max = 3;
	I2C_MasterTransferData(LPC_I2C, &transferMCfg, I2C_TRANSFER_POLLING);
}
예제 #23
0
int read_busy_flag_display(int i2c_port){

    uint8_t write[1];
    write[1] = 0x80;
    int receive[1];
    I2C_M_SETUP_Type TransferCfg;
    TransferCfg = setup_TransferCfg(TransferCfg, i2c_port, write, 1, receive, 1);
    I2C_MasterTransferData(usedi2c, &TransferCfg, I2C_TRANSFER_POLLING);
    receive[1] &= 0x80;
    if (receive[1] == 0x80){
        return 1; // busy is true
    }
    else{
        return 0;
    }
}
예제 #24
0
파일: i2c.c 프로젝트: Q-Mart/EMPR
int i2c_recv_mbed_polling(int lpc, int addr, int len, char* buf)
{
    I2C_M_SETUP_Type cfg;
    cfg.tx_data = NULL;
    cfg.tx_length = 0;
    cfg.rx_data = buf;
    cfg.rx_length = len;
    cfg.retransmissions_max = 3;
    cfg.sl_addr7bit = addr;

    Status s = I2C_MasterTransferData(get_i2c_ptr(lpc), &cfg, I2C_TRANSFER_POLLING);

    if (s == SUCCESS)
        return 1;

    return 0;
}
예제 #25
0
void UDA_Reg_write(UDA1380_REG reg, unsigned short value){
  I2C_M_SETUP_Type transferMCfg;
  UNS_8  tx_data[3];
  tx_data[0] = reg;
  tx_data[1] = value>>8;
  tx_data[2] = value&0xFF;
//  i2c_mtx_setup.addr_mode = ADDR7BIT;
  transferMCfg.sl_addr7bit = (0x34>>1);//I2CDEV_UDA1380_ADDR
  transferMCfg.tx_data = &tx_data[0];
  transferMCfg.tx_length = 3;
  transferMCfg.rx_data = NULL;
	transferMCfg.rx_length = 0;
  transferMCfg.retransmissions_max = 5;
  I2C_MasterTransferData(LPC_I2C, &transferMCfg, I2C_TRANSFER_POLLING);
  //while (( i2c_mtx_setup.status & I2C_SETUP_STATUS_DONE) == 0);
  delay(10000);
}
예제 #26
0
/*
Pre-Reqs:setupI2C1()
Desc: Sends some data of a given size to a given address on the I2C bus
Inputs: char* strPtr - Pointer to the string
		char[BUFFLENGTH] - String of length BUFFLENGTH
*/
void sendToI2C1(uint32_t i2caddress, uint8_t* tx_dat, uint8_t size){
	char* strPtr;
	char msg[BUFFLENGTH] = "";
	strPtr = &msg;
	int num = 0;

	I2C_M_SETUP_Type TransferCfg;

	TransferCfg.sl_addr7bit = i2caddress;
	TransferCfg.tx_data = tx_dat;
	//TransferCfg.retransmissions_max = 5;
	TransferCfg.tx_length = sizeof(uint8_t)*size;
	TransferCfg.rx_data = NULL;
	TransferCfg.rx_length = 0;

	I2C_MasterTransferData((LPC_I2C_TypeDef *)LPC_I2C1, &TransferCfg, I2C_TRANSFER_POLLING);
}
예제 #27
0
unsigned short UDA_Reg_read(UDA1380_REG reg){
  I2C_M_SETUP_Type transferMCfg;
  unsigned char TXdata, RXdata[2];
  unsigned short result=0;
	TXdata = reg;
//    transferMCfg.addr_mode = ADDR7BIT;
    transferMCfg.sl_addr7bit = (0x34>>1);//I2CDEV_UDA1380_ADDR
    transferMCfg.tx_data = &TXdata;
    transferMCfg.tx_length = 1;
    transferMCfg.rx_data = &RXdata[0];
    transferMCfg.rx_length = 2;
    transferMCfg.retransmissions_max = 5;
    I2C_MasterTransferData(LPC_I2C, &transferMCfg, I2C_TRANSFER_POLLING);
    //while (( i2c_mtxrx_setup.status & I2C_SETUP_STATUS_DONE) == 0);
    result = RXdata[0]<<8 | RXdata[1];
	return result;
}
예제 #28
0
int _I2C_MasterTransferData(uint8_t * args)
{
	uint8_t * arg_ptr;
	LPC_I2C_TypeDef* I2Cx;
	I2C_M_SETUP_Type* TransferCfg;
	I2C_TRANSFER_OPT_Type Opt;

	if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
	I2Cx = (LPC_I2C_TypeDef*) strtoul((char *) arg_ptr, NULL, 16);
	if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
	TransferCfg = (I2C_M_SETUP_Type*) strtoul((char *) arg_ptr, NULL, 16);
	if ((arg_ptr = (uint8_t *) strtok(NULL, " ")) == NULL) return 1;
	Opt = (I2C_TRANSFER_OPT_Type) strtoul((char *) arg_ptr, NULL, 16);

	sprintf((char *) str, "%x\r\n", (unsigned int) I2C_MasterTransferData(I2Cx, TransferCfg, Opt));
	writeUSBOutString(str);
	return 0;
}
예제 #29
0
void TSC2007_Init(void)
{
    I2C_M_SETUP_Type transfer;
    uint8_t command;

    I2C_Init(TSC_I2C, 400000);
    I2C_Cmd(TSC_I2C, ENABLE);

    // Send 'setup' command
    command = 0xB0; // MAV filter enabled, Rirq=50kOhm
    transfer.sl_addr7bit = TSC_SLA;
    transfer.tx_data = &command;
    transfer.tx_length = 1;
    transfer.rx_data = 0;
    transfer.rx_length = 0;
    transfer.retransmissions_max = 1;   // no ACK on this command
    I2C_MasterTransferData(TSC_I2C, &transfer, I2C_TRANSFER_POLLING);
}
예제 #30
0
int _readAccel(uint8_t* args)
{    
    uint8_t          receive_buffer[6];
    I2C_M_SETUP_Type setup;
    int16_t*         axis_data;
    Status           result;
    uint8_t          transmit_buffer;
    uint8_t          axis_enable_bit;

    setup.sl_addr7bit         = ACCEL_I2C_SLAVE_ADDRESS;
    setup.retransmissions_max = MAX_ST_I2C_RETRANSMISSIONS;

    setup.tx_data   = &transmit_buffer;
    setup.tx_length = 1;
    setup.rx_data   = receive_buffer;
    setup.rx_length = 6;

    transmit_buffer = ACCEL_DATA_ADDRESS|ST_I2C_AUTOINCREMENT_ADDRESS;

    result = I2C_MasterTransferData(LPC_I2C0, &setup, I2C_TRANSFER_POLLING);
    if(result == ERROR)
        return 1;

    axis_enable_bit = ACCEL_CTRL_REG_X_ENABLE;
    axis_data       = (int16_t*)receive_buffer;

		unsigned int value[3];
		int index=0;
    do
    {
        if(accel_ctrl_reg_1_a_value&axis_enable_bit)
        {
            value[index++] = (unsigned int)(*axis_data+ACCEL_VALUE_OFFSET);
        }

        axis_enable_bit <<= 1;
        axis_data++;
    }while(axis_enable_bit <= ACCEL_CTRL_REG_Z_ENABLE);

		sprintf((char*)str, "%x %x %x\r\n", value[0],value[1],value[2]);
    writeUSBOutString(str);
    
    return 0;
}