End of Year Sale 2014
It is currently 22 Dec 2014 22:18

All times are UTC + 1 hour




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: 14 Feb 2011 20:03 
Offline

Joined: 13 Feb 2009 09:03
Posts: 65
Location: Germany
I used your HID Read Write Interrupt example for the first USB trials. It worked without major problems - thank you for this.

But when I adapted the example I encountered a problem. I added one line

      ...
      for(cnt=0;cnt<64;cnt++)
      writebuff[cnt]=readbuff[cnt];

    while(!HID_Write(&writebuff,64));
    writebuff[0] = 66;           // New line, this data will be written!
  }
}
and saw in the HID terminal that the first received character is always the 'B'. But since the writebuff[0] = 66 line is executed after "data is successfuly sent" (citation from help) the behaviour is not correct in my opinion. To make it more clear I add a screenshot.
Attachment:
HID-Example.jpg
HID-Example.jpg [ 122.69 KiB | Viewed 1027 times ]
I think the additional line must have no influence. What do you think?

Thanks and Best Regards
absalom


Top
 Profile  
 
PostPosted: 14 Feb 2011 20:38 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3349
Location: Nieuwpoort, Belgium
I was a little bit afraid this would happen sooner or later. The reason is that the main program uses the USB buffers directly (at 0x500 and 0x540). Additionally I think that "HID_Write" returns true if the sendbuffer is free, that is the previous transmission is executed. It is very well possible that the current one is still pending and changing the buffer contents has indeed some effect...

_________________
Kind regards,
Dany.
(happy user of mP PRO for PIC and dsPIC30/33 and PIC24, PicFlash2, RTClock, Max232 board, Ethernet PROTO board, MMC/SD Card Proto board, Yo2Lio's and Janni's libs)
http://www.rosseeld.be/DRO/PIC/index.htm


Top
 Profile  
 
PostPosted: 15 Feb 2011 19:17 
Offline

Joined: 13 Feb 2009 09:03
Posts: 65
Location: Germany
That would be painful! Do you know another way to check if the write buffer is ready for new data (apart from waiting for an acknowledge message from the host)?
Looking forward to read also a statement from the mE team.
Thanks
absalom


Top
 Profile  
 
PostPosted: 16 Feb 2011 10:30 
Offline

Joined: 22 Jul 2008 08:50
Posts: 87
Location: Serbia
Function:
while(!HID_Write(&writebuff,64));

is blocking call and line
writebuff[0] = 66;           // New line, this data will be written!

have no effect because USB write procedure is ended!
Change write buffer before HID_write call.


Top
 Profile  
 
PostPosted: 16 Feb 2011 10:39 
Offline

Joined: 13 Feb 2009 09:03
Posts: 65
Location: Germany
yt7pwr wrote:
Function:
while(!HID_Write(&writebuff,64));

is blocking call and line
writebuff[0] = 66;           // New line, this data will be written!

have no effect because USB write procedure is ended!
Change write buffer before HID_write call.

Unfortunately it has an effect as described above. That is the reason for opening this thread.
Or do you test the described example?


Top
 Profile  
 
PostPosted: 16 Feb 2011 12:46 
Offline

Joined: 22 Jul 2008 08:50
Posts: 87
Location: Serbia
Maybe I was not clear: your code is wrong.No point to change one write buffer
byte after HID_write when your loop will rewrite all bytes!
Try this:
while{1}
{
while(!HID_Read());                        // this is blocking call! try polling method instead
    for(cnt=0;cnt<64;cnt++)
      writebuff[cnt]=readbuff[cnt];     // rewrite all bytes!
    writebuff[0] = 66;                      // change only one byte!
    while(!HID_Write(&writebuff,64)); // send buffer via USB link
    writebuff[0] = 66;                      // this line have no effect!
  }


Top
 Profile  
 
PostPosted: 16 Feb 2011 13:26 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3349
Location: Nieuwpoort, Belgium
yt7pwr wrote:
    writebuff[0] = 66;                      // this line have no effect!
The issue here is that it has effect, while no effect is expected.

_________________
Kind regards,
Dany.
(happy user of mP PRO for PIC and dsPIC30/33 and PIC24, PicFlash2, RTClock, Max232 board, Ethernet PROTO board, MMC/SD Card Proto board, Yo2Lio's and Janni's libs)
http://www.rosseeld.be/DRO/PIC/index.htm


Top
 Profile  
 
PostPosted: 17 Feb 2011 10:22 
Offline
mikroElektronika team
User avatar

Joined: 07 Apr 2009 09:39
Posts: 1321
Hi!

Currently, I can only agree with Dany and yt7pwr.
The problematic line is obviously written in the wrong place but it should not have any effect.
I'll contact our more experienced colleagues regarding this issue and I'll get back to you.

_________________
Best regards
Slavisa


Top
 Profile  
 
PostPosted: 22 Feb 2011 10:11 
Offline

Joined: 12 May 2010 10:35
Posts: 256
Location: Sinny, Straya
I reported a very similar (if not identical) problem in September 2010 (ticket number VUT-955119) but it must have slipped under the radar! I did come up with a workaround which I described then as:

Quote:
I've got another workaround for this problem (of not being able to execute 2
USB HID_Write calls without an intervening 1 ms delay). I've found that if I
code (pseudo code):

buffer1 = 'x'
while (!HID_Write(buffer1,1));
buffer2 = 'y'
while(!HID_Write(buffer2,1));


...then it works correctly: the host receives 'x' and then 'y'. Also, if I
code a 1 ms delay between 2 sends from the *same* buffer, it works -
although more slowly due to the 1 ms delay.

But if I code:

buffer = 'x'
while(!HID_Write(buffer,1));
buffer = 'y'
while(!HID_Write(buffer,1));


...then there is a high probability that 'y' is written to the USB host 2
times, and 'x' never reaches the host.

I'm sure (as I can be) that I cannot trust the return value from HID_Write
(the number of bytes written to the USB host) as meaning "I can now update
the send buffer".

When HID_Write returns (indicating the number of bytes sent) it should mean
that I can immediately send the next buffer, yes?

I've attached a minimal project that works (using two buffers)

_________________
Regards, android
(User of MikroC Pro + mikroProg)


Top
 Profile  
 
PostPosted: 22 Feb 2011 19:58 
Offline

Joined: 13 Feb 2009 09:03
Posts: 65
Location: Germany
Thanks for the info android, that is really interesting.
I hope mE handles this topic with more priority in future ..


Top
 Profile  
 
PostPosted: 10 Mar 2012 12:46 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3349
Location: Nieuwpoort, Belgium
slavisa.zlatanovic wrote:
Currently, I can only agree with Dany and yt7pwr.
The problematic line is obviously written in the wrong place but it should not have any effect.
I'll contact our more experienced colleagues regarding this issue and I'll get back to you.

Hi Slavisa, I can not reproduce this problem any more in mP v5.40, I do not know about mC.

Can you confirm it has indeed been solved?
Has the routine "HID_Write" changed to a blocking one?

Thanks in advance! :D

_________________
Kind regards,
Dany.
(happy user of mP PRO for PIC and dsPIC30/33 and PIC24, PicFlash2, RTClock, Max232 board, Ethernet PROTO board, MMC/SD Card Proto board, Yo2Lio's and Janni's libs)
http://www.rosseeld.be/DRO/PIC/index.htm


Top
 Profile  
 
PostPosted: 10 Mar 2012 13:31 
Offline

Joined: 12 May 2010 10:35
Posts: 256
Location: Sinny, Straya
Hi Dany,

By sheer coincidence I came to the conclusion just today that the problem has been fixed by 5.4 ...I no longer need to use two different buffers to send key pressed/key not pressed reports.

:)

_________________
Regards, android
(User of MikroC Pro + mikroProg)


Top
 Profile  
 
PostPosted: 10 Mar 2012 18:14 
Offline

Joined: 18 Jun 2008 11:43
Posts: 3349
Location: Nieuwpoort, Belgium
android wrote:
Hi Dany,

By sheer coincidence I came to the conclusion just today that the problem has been fixed by 5.4 ...I no longer need to use two different buffers to send key pressed/key not pressed reports.

:)
Ha! Thanks!! :D :D

_________________
Kind regards,
Dany.
(happy user of mP PRO for PIC and dsPIC30/33 and PIC24, PicFlash2, RTClock, Max232 board, Ethernet PROTO board, MMC/SD Card Proto board, Yo2Lio's and Janni's libs)
http://www.rosseeld.be/DRO/PIC/index.htm


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Exabot [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group