Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

USB low-full-high speed peripherals

Chris_Hawthorne
Level 3
25 sign-ins 10 replies posted 10 sign-ins
Level 3

I have a project that I am developing using the FX2 platform to read an I2C based encoders.  The system will host five different encoders which are read by the I2C bus and I would like to read their data buffer and place into a buffer to be read back by the computer when you do a bulk read.  This way each transaction on the USB bus yields the buffer contents of all five encoders.  I was trying to write the return of EZUSBReadI2C into EP2FIFOBUF but EP2FIFOBUF won't accept the data.

0 Likes
1 Solution
Chris_Hawthorne
Level 3
25 sign-ins 10 replies posted 10 sign-ins
Level 3

Hi Yatheesh,

I was able to get the firmware to work the way I would like it to.  Thank you for the help.  To correct the return value changing from the default value to 1 instead of incrementing the default value when the encoder is turned, I added a second programming of the initial values using a EZUSB_WriteI2C(encoder, 17, (WORD)Setup_Data); .  Not reala second time.  I am not sure why this works but it does.  To get the unit to load defaults without a Vendor Request I added if(!(ENCODER_RDY))initialize_encoder(); to TD_Poll().  Now when I plug the unit in the encoders read correctly and there is no need for a vendor request unless you want to reset the default values.  Thanks for all the help!

void initialize_encoder()

{

int i, ii, iii;

BYTE Status;

BYTE xdata Setup_Data[17];

WORD Read_Data;

ii = 0;

iii =1;

//Reset the FIFO

FIFORESET = 0x80;

SYNCDELAY;

FIFORESET = 0x02;

SYNCDELAY;

FIFORESET = 0x00;

SYNCDELAY;

//Fill Encoder_Data with Setup contents

for (i=0; i < ENCODER_N; i++){

counter = default_counter;

Setup_Data[0] = 0x00; //Register to Start

Setup_Data[1] = 0x0B; //General Config

Setup_Data[2] = 0x00; //Status

Setup_Data[3] = 0x00; //Counter Byte 4

Setup_Data[4] = 0x00; //Counter Byte 3

Setup_Data[5] = 0x00; //Counter Byte 2

Setup_Data[6] = 0x00; //Counter Byte 1

Setup_Data[7] = 0x00; //Max Byte 4

Setup_Data[8] = 0x00; //Max Byte 3

Setup_Data[9] = 0xFF; //Max Byte 2

Setup_Data[10] = 0xFF; //Max Byte 1

Setup_Data[11] = 0x00; //Min Byte 4

Setup_Data[12] = 0x00; //Min Byte 3

Setup_Data[13] = 0x00; //Min Byte 2

Setup_Data[14] = 0x00; //Min Byte 1

Setup_Data[15] = 0x00; //LED A

Setup_Data[16] = 0x00; //LED B

Setup_Data[5] = MSB(default_counter); //Counter Byte 2

Setup_Data[6] = LSB(default_counter); //Counter Byte 1

EZUSB_WriteI2C(encoder, 17, (WORD)Setup_Data);

EZUSB_WaitForEEPROMWrite(encoder);

EZUSB_WriteI2C(encoder, 17, (WORD)Setup_Data);

EZUSB_WaitForEEPROMWrite(encoder);

Status = Encoder_Status(encoder);

Read_Data = Encoder_Read_Word(encoder, DATA_COUNTER_BYTE2);

counter = default_counter;

if(Read_Data != counter){// && (ENCODER_RDY)){

Encoder_LED(encoder, DECREASE, 500);

}

EP2FIFOBUF[ii] = LSB(Read_Data);

EP2FIFOBUF[iii] = MSB(Read_Data);

ii = ii + 2;

iii = iii + 2;

Encoder_LED(encoder,INCREASE, 50);

}

for (i=10;i<16;i++){

EP2FIFOBUF=0xFF;

}

ENCODER_RDY = TRUE;

}

View solution in original post

0 Likes
15 Replies