Ejemplo n.º 1
0
void iic_Receive (u8 slvAddress, iic_ptr eotCB, iic_ptr commFailedCB, u8 toRead, u8* receiveBuffer)
{
	if (iic_IsBusy())
	{
		if (iic_data.stoppingBus)	// If the bus is busy but not because it is being stopped, it's a logical error.
	    	while (iic_IsBusy()); 						// Wait until bus stop is complete
	    else
	    	err_Throw("iic: attempt to receive message while bus is busy.\n");
	}
	
	iic_data.stoppingBus = _FALSE;     
    iic_data.eotCB = eotCB;
    iic_data.commFailedCB = commFailedCB;
    iic_data.currCB = iic_read_start;
    iic_data.dataIdx = 0;
    
    iic_commData.dataSize = toRead-1;		// toRead es lo que quiero leer, el -1 es necesario para eso.
 	
 	if (receiveBuffer != NULL)
	 	iic_commData.dataPtr = receiveBuffer;
    else
    	iic_commData.dataPtr = iic_commData.data;
    
    IIC_SET_AS_TX();
    
    IIC_START();
    IIC_SEND((slvAddress << 1) + READ);		//precedence
}
Ejemplo n.º 2
0
void iic_Send (u8 slvAddress, iic_ptr eotCB, iic_ptr commFailedCB, u8 toSend, u8* sendBuffer)
{
	if (iic_IsBusy())
	{
		if (iic_data.stoppingBus)	// If the bus is busy but not because it is being stopped, it's a logical error.
	    	while (iic_IsBusy()); 						// Wait until bus stop is complete
	    else
	    	err_Throw("iic: attempt to send message while bus is busy.\n");
	}
	
	iic_data.stoppingBus = _FALSE;     
    iic_data.eotCB = eotCB;
    iic_data.commFailedCB = commFailedCB;
    iic_data.currCB = iic_write;
    iic_data.dataIdx = 0;
    
    iic_commData.dataSize = toSend-1;	// 	New version: dataSize received as parameter for compatibility with receive.
        								//	As before, toSend is the size (to send 1 byte, toSend has to be 1), so the (-1) is for compatibility.
 	if (sendBuffer != NULL)
	 	iic_commData.dataPtr = sendBuffer;
    else
    	iic_commData.dataPtr = iic_commData.data;
    
    IIC_SET_AS_TX();
    
    IIC_START();
    IIC_SEND((slvAddress << 1) + WRITE);
}
Ejemplo n.º 3
0
void IIC_MasterRW(IIC_StatType stat,uint8_t slave_addr,uint8_t reg_addr,uint16_t length,uint8_t* data)
{
	if(IIC_Status.sw == IIC_Switch_Pause)return;
	//wait until free
	while(IIC_Status.i2cstat == IIC_I2CStat_Busy);
	IIC_Status.stat = stat;
	IIC_Status.step = IIC_Step_Call;
	IIC_Status.slave_addr = slave_addr;
	IIC_Status.reg_addr = reg_addr;
	IIC_Status.queuelength = length;
	IIC_QueuePointer = 0;
	IIC_Queue = data;
	IIC_START();
}
Ejemplo n.º 4
0
bool iic_receive (u8 slvAddress, iic_ptr eotCB, iic_ptr commFailedCB, u8 toRead)
{
	if ((iic_isBusy()) && (iic_data.stoppingBus))
    	while (iic_isBusy()); // Se espera a que se termine de liberar el bus     
        	   
	iic_data.stoppingBus = _FALSE;    
	
    iic_data.eotCB = eotCB;
    iic_data.commFailedCB = commFailedCB;
    iic_data.currCB = iic_read_start;
    iic_data.dataIdx = 0;
    
    iic_commData.dataSize = toRead-1;
    
    IIC_SET_AS_TX();
    
    IIC_START();
    IIC_SEND((slvAddress << 1) + READ);		//precedence
    
    return _TRUE;
}
Ejemplo n.º 5
0
bool iic_send (u8 slvAddress, iic_ptr eotCB, iic_ptr commFailedCB)
{
    if ((iic_isBusy()) && (iic_data.stoppingBus))
    	while (iic_isBusy()); // Se espera a que se termine de liberar el bus     
        	   
	iic_data.stoppingBus = _FALSE;    
    
    iic_data.eotCB = eotCB;
    iic_data.commFailedCB = commFailedCB;
    iic_data.currCB = iic_write;
    iic_data.dataIdx = 0;
    
    iic_commData.dataSize--;
    
    IIC_SET_AS_TX();
    
    IIC_START();
    IIC_SEND((slvAddress << 1) + WRITE);

    return _TRUE;
}