SEARCH
TOOLBOX
LANGUAGES
Register    Login    Forum    Search    FAQ

Board index » Electronics Projects » PIC18F USB development




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Stuck on work with accelerometer
 Post Posted: Tue Mar 29, 2011 3:11 am 
Offline

Joined: Tue Mar 29, 2011 2:48 am
Posts: 1
Hi,

I`m working on a project that involves sending x, y, z coordinates to a host software.

Using the standard CCS I wore a simple code that keeps looping sending 1 ; ow x; 2;y; 3;z ... I know it`s working because I test it with the Microsoft SDK and it`s giving me the numbers...

Now I want to do a host application... but I`m stuck in the beggining...I just need a first step.....to move on....

here is the main sub of my firmware:

while (TRUE) {
usb_task();
usb_debug_task();
if (usb_enumerated()) {
if (!send_timer) {
send_timer=250;

// Editado. Muda canal do ADC e envia p HOST (pmb)

switch (a) {

case 1:set_adc_channel(1);
a = 2;
break;

case 2:set_adc_channel(2);
a = 3;
break;

case 3:set_adc_channel(3);
a = 1;
break;
}

out_data[0]=a;
out_data[1]=read_adc();


//out_data[1]=!input(BUTTON);
if (usb_put_packet(1, out_data, 2, USB_DTS_TOGGLE))
printf("\r\n<-- Sending 3 bytes: 0x%X 0x%X", out_data[0], out_data[1]);
}
if (usb_kbhit(1)) {
usb_get_packet(1, in_data, 2);
printf("\r\n--> Received data: 0x%X 0x%X",in_data[0],in_data[1]);
if (in_data[0]) {LED_ON(LED2);} else {LED_OFF(LED2);}
if (in_data[1]) {LED_ON(LED3);} else {LED_OFF(LED3);}
}
send_timer--;
delay_ms(1);
}
}
}


And here is how I`m tring to get the data on to a simple label....but not being able to go trough..

I`ve just copyed part of the code (part of it is exactly as in the example...copyed part just to localize it on the original code)

private: System::Void usbStateMonitoringTimer_Tick(System::Object^ sender, System::EventArgs^ e)
{
// Check if the USB device is attached and update the form accordingly
if (a_usbHidCommunication.isDeviceAttached() == true)
{


// Status strip update
this->usbStatusLabel->Text = L"USB Device Attached";


// Check the status of the switch

unsigned char TESTE = a_usbHidCommunication.readFromTheInputBuffer(1);//PMB

TESTE= a_usbHidCommunication.readFromTheInputBuffer(2); //pmb

//string s;
//s = s + TESTE;
//this->label1->Text = s ;


It wont display on the label at all....but the imput array is not being filled with any info that looks like the x, y an z coordinates.

Would appreciate any help,

Thanks for all!


Top 
 Profile  
 
 Post subject: Re: Stuck on work with accelerometer
 Post Posted: Tue Mar 29, 2011 5:09 am 
Offline

Joined: Thu Apr 01, 2010 6:23 am
Posts: 898
It looks like you are simply sending data from the device and then expecting to see the data on the host which is not correct.

On the host poll (the timer tick) you need to send a command to the device (like 0x80 in my examples) when the device receives the command it fills the output buffer with the appropriate data and then responds. In USB HID the host must always initiate communication with a command, the device cannot simply fill the output buffer whenever it likes.

Look again at some of the USB projects on my site and you will see how it works :)


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

Board index » Electronics Projects » PIC18F USB development


Who is online

Users browsing this forum: No registered users and 0 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:  
cron
Translated by MaĆ«l Soucaze © 2009 phpBB.fr