Esempio n. 1
0
uint32 writeSequencerBoard(void)
{
    uint32 status = I2C_TRANSFER_ERROR; 
    
    I2CM_I2CMasterWriteBuf(SEQUENCER_I2C_SLAVE_ADDRESS,
        sequencerWrBuffer,
        SEQUENCER_I2C_WR_BUFFER_SIZE,
        I2CM_I2C_MODE_COMPLETE_XFER
    );
    while (0u == (I2CM_I2CMasterStatus() & I2CM_I2C_MSTAT_WR_CMPLT))
    {
        /* Waits until master completes read transfer */
    }
    
    /* Displays transfer status */
    if (0u == (I2CM_I2C_MSTAT_ERR_XFER & I2CM_I2CMasterStatus()))
    {
        RGB_LED_ON_GREEN;

        /* Check if all bytes was written */
        if (I2CM_I2CMasterGetWriteBufSize() == SEQUENCER_I2C_WR_BUFFER_SIZE)
        {
            status = I2C_TRANSFER_CMPLT;
        }
    }
    else
    {
        RGB_LED_ON_RED;
    }

    (void) I2CM_I2CMasterClearStatus();
    
    return status;   
}
Esempio n. 2
0
uint32 LCD_Write(uint8 *buffer)
{
	uint32 status = I2C_TRANSFER_ERROR;
	
    I2CM_I2CMasterWriteBuf(LCD_I2C_SLAVE_ADDRESS,
        buffer,
        LCD_I2C_PACKET_SIZE,
        I2CM_I2C_MODE_COMPLETE_XFER
    );
    while (0u == (I2CM_I2CMasterStatus() & I2CM_I2C_MSTAT_WR_CMPLT))
    {
        /* Waits until master completes write transfer */
    }

    /* Displays transfer status */
    if (0u == (I2CM_I2C_MSTAT_ERR_XFER & I2CM_I2CMasterStatus()))
    {
        RGB_LED_ON_GREEN;

        /* Check if all bytes was written */
        if(I2CM_I2CMasterGetWriteBufSize() == LCD_I2C_BUFFER_SIZE)
        {
            status = I2C_TRANSFER_CMPLT;
			
			// 1命令ごとに余裕を見て50usウェイトします。
			CyDelayUs(50);	
        }
    }
    else
    {
        RGB_LED_ON_RED;
    }

    (void) I2CM_I2CMasterClearStatus();
	   
	return (status);
}
Esempio n. 3
0
uint8 Camera_read(void)
{
    uint32 status = I2CM_I2C_MSTR_NO_ERROR;
	uint8 rxdata[16] = {0};
	
	I2CM_I2CMasterClearStatus();
	
	//IR sensor read
    status = I2CM_I2CMasterSendStart(IRslaveAddress, 0);
	if (status != I2CM_I2C_MSTR_NO_ERROR)
	{return 0;}
	
    status = I2CM_I2CMasterWriteByte(0x36);
	if (status != I2CM_I2C_MSTR_NO_ERROR)
	{return 0;}
	
    status = I2CM_I2CMasterSendStop();
	if (status != I2CM_I2C_MSTR_NO_ERROR)
	{return 0;}
	
	CyDelayUs(10);
	
	status = I2CM_I2CMasterReadBuf(IRslaveAddress, &rxdata[0], 16, I2CM_I2C_MODE_COMPLETE_XFER);
	if (status != I2CM_I2C_MSTR_NO_ERROR)
	{return 0;}
	
	while(I2CM_I2CMasterStatus() != I2CM_I2C_MSTAT_RD_CMPLT);
	
    for (i=0; i<16; i++)
    {
		data_buf[i]=0;
		data_buf[i] = rxdata[i];
    }

    blobcount = 0;

    Blob1.X = data_buf[1];
    Blob1.Y = data_buf[2];
    s   = data_buf[3];
    Blob1.X += (s & 0x30) <<4;
    Blob1.Y += (s & 0xC0) <<2;
    Blob1.Size = (s & 0x0F);

    // At the moment we're using the size of the blob to determine if one is detected, either X,Y, or size could be used.
    blobcount |= (Blob1.Size < 15)? BLOB1 : 0;

    Blob2.X = data_buf[4];
    Blob2.Y = data_buf[5];
    s   = data_buf[6];
    Blob2.X += (s & 0x30) <<4;
    Blob2.Y += (s & 0xC0) <<2;
    Blob2.Size = (s & 0x0F);

    blobcount |= (Blob2.Size < 15)? BLOB2 : 0;

    Blob3.X = data_buf[7];
    Blob3.Y = data_buf[8];
    s   = data_buf[9];
    Blob3.X += (s & 0x30) <<4;
    Blob3.Y += (s & 0xC0) <<2;
    Blob3.Size = (s & 0x0F);

    blobcount |= (Blob3.Size < 15)? BLOB3 : 0;

    Blob4.X = data_buf[10];
    Blob4.Y = data_buf[11];
    s   = data_buf[12];
    Blob4.X += (s & 0x30) <<4;
    Blob4.Y += (s & 0xC0) <<2;
    Blob4.Size = (s & 0x0F);

    blobcount |= (Blob4.Size < 15)? BLOB4 : 0;

    return blobcount;
}