PICcoder.co.uk Forum  


::post new topic::
PIC18f4550 data retrieval
Date: 2006/10/18 17:57 By: Tyler Status: Visitor  
 
Hey Mat, I really appreciate the comprehensive tutorial you have explaining USB. Now, I understand the code for the most part, but I'm somewhat puzzled on how to approach a design problem I have. Essentially what I need to accomplish is to retrieve data from another microcontroller and transfer that via USB. The data would mostly be text. So I was just wondering how I would for example, have a string saying "Hello World" coming into one of the ports on the 18f4550, and then in the C# being able to press a button and have that text appear in a text box.
reply | quote

Re:PIC18f4550 data retrieval
Date: 2006/10/20 00:17 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
Hmmm, that's going to be some great work.

You should choose a protocol and a medium between the 2 CPUs, say RS232 or I2C, and then use USB framework (and corresponding C# or C++ software/DLL) to read them on the PC.

I'd suggest "emulating" the CPU to CPU communication, thus sending a fixed or incrementing string to the PC at the touch of a button, and LATER implement the other part.
reply | quote

Re:PIC18f4550 data retrieval
Date: 2006/10/22 00:10 By: Tyler Status: Visitor  
 
Yes, I was thinking along the same lines of I2C. I'm just trying to work my way through slowly.
reply | quote

Re:PIC18f4550 data retrieval
Date: 2006/10/22 18:18 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
Yeah, implementing I2C slave is not difficult, only somewhat "time-careful" in the sense you always have to check if the host is Calling for you. I2C master is OTOH very easy, either via hardware or bit-banging.

I found an app-note years ago, and adapted it to create an I2C LCD display with a small protocol. Then I ported to C.

If you need hints and can't find other App notes, let me know.
reply | quote

Re:PIC18f4550 data retrieval
Date: 2006/10/22 19:06 By: Tyler Status: Visitor  
 
Now my question is, since i'm using the dsPIC30F3011 and the PIC18f4550, wouldn't the master have to be the 18f4550, because that is the PIC that will have to initialze the data transfer from the dsPIC30f3011 to itself, and then from there to the PC via USB.
reply | quote

Re:PIC18f4550 data retrieval
Date: 2006/10/24 09:55 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
yes, definitely I say yes, because of what you mention and also because having the USB-micro perform as a I2C slave would be cumbersome... it is already a slave to the PC, thus needs to answer USB transaction in strict timing...

Possibly, let the dsPic do its core work and poll for I2C regularly (around 1mSec)
reply | quote

Re:PIC18f4550 data retrieval
Date: 2006/10/24 15:54 By: Tyler Status: Visitor  
 
Hey thanks a lot for responding dariog. I guess I can see how the higher level processes will work together. I am confused about one basic thing, let say i have a string that says "hello world" stored on the 18f4550 as a variable just to simplify things, would i use the dataPacket command on the PIC side to actually send the string. That's basically what isn't making sense right now, how the PIC side software is interacting with the C# platform.
reply | quote

Re:PIC18f4550 data retrieval
Date: 2006/10/25 04:54 By: Tyler Status: Visitor  
 
This is how I modified the code to just transmit a character stored into memory and it doesn't seem to be working.

in user.h
Code:

         enum         {             READ_VERSION   0x00,             ID_BOARD           0x31,             UPDATE_LED      0x32,             GET_STRING      0x33,             DO_SUM           0xEE,             RESET           0xFF         }CMD;



in user.c I have
Code:

  case GET_STRING:     char x[1] = 'H';     dataPacket._byte[1] = 0x02;     dataPacket._byte[2] = x[1];     counter 0x03;



in usb_interface.cs I have
Code:

  public uint GetString()         {                         bytesend_buf=stackalloc byte[64];             bytereceive_buf=stackalloc byte[64];                         int Temp 0;                          DWORD RecvLength=(byte)3;             send_buf[0] = 0x33                         if (SendReceivePacket(send_buf,3,receive_buf,&RecvLength) == 1)             {                 Temp receive_buf[2];             }                      return Temp; }

reply | quote

Re:PIC18f4550 data retrieval
Date: 2006/10/26 22:06 By: dariog Status: User  
Karma: 6  
Posts: 107
graphgraph
oops, I'm sorry: I'm not using C# nor MPUSBAPI...
In C++, you'd have a ReadFile which waits for data from the PIC; thus, to avoid stopping the whole program, it is put in a separate task and let her notify to the main prog.

I cant' provide you code for your platform, but someone else here around should have done that...

PS: in your PIC code, aren't you missing the "real" TxBuf function (whatever it is colled, HIDTXReport i.e. in HID example from Microchip) ?
reply | quote

::post new topic::