Hello all!
I use the DLP-2332PB for development of the data acquisition device. Using the internal A/D converters of the PIC I would like to sample the incoming analog signal with the rate of 20MHz(per single channel)-1kHz. The PIC-side code was written using CCS complier supplied with the device. The host-side code written using C# 2.0 compiler and PInvoke facilities. Device driver is FTD2XX. I use the following simple application for the communication test:
2332PB-side:#include #device ADC=10 #fuses HS,NOWDT,NOPUT,NOBROWNOUT,LVP,NOWRT,NOPROTECT #use delay(clock=20000000) #use FAST_IO(D) #use FAST_IO(C) #use FAST_IO(B) #use FAST_IO(A) #use FAST_IO(E)
#define WR PIN_B2 #define RD PIN_B1 #define SND PIN_E1 #define TXE PIN_E2 #define RXF PIN_B4
#byte PORTD = 0x08
#inline void write_byte(int data);
void main() { long count=0; SET_TRIS_B(0x11); SET_TRIS_E(0x04); output_high(RD);
while(TRUE) { SET_TRIS_D(0xff); while(input(RXF)) ; SET_TRIS_D(0x00); while(!input(TXE) && count < 255) { write_byte(1); count++; write_byte(2); count++; write_byte(3); count++; write_byte(4); count++; } } }
#inline void write_byte(int data) { PORTD = data; delay_us(1); output_low(WR); delay_us(1); output_high(WR); }
The code is supposed to send 256 bytes of data with "1,2,3,4,1,2,3..." pattern to PC after receiving anything from the PC side. __________________________________ host side:
using System; using System.Collections.Generic; using System.Text; using FTDIWrapper; namespace tryPIC { class Program { static void Main(string[] args) { while(true) { while (!Wrapper.OpenDevice()) ; Wrapper.PurgeAll(); Wrapper.ReadData(Wrapper.CheckQueue()); Wrapper.WriteData(new byte[] { 0 }); System.Threading.Thread.Sleep(100); byte[] data = Wrapper.ReadData(Wrapper.CheckQueue()); while(!Wrapper.CloseDevice()) ; Console.WriteLine("Data:"); for (int i = 0; i < data.Length; i++) { Console.WriteLine("byte #{0} is {1}", i, data[i]); } Console.WriteLine("Continue? (y/n)"); if(Console.ReadLine()!="y") break; } } } }
And the "Wrapper" functions are calls to unmanaged code using DllImport attributes. Functions' signatures are:
public static void WriteData(byte[] data); public static byte[] ReadData(uint bytesToReceiveNum); public static uint CheckQueue(); public static void PurgeAll(); public static bool OpenDevice(); public static bool CloseDevice();
This program sends "request" (any garbage) to the microcontroller, waits approximately 100 milliseconds , then reads the contents of the driver's buffer and prints it on the screen. This continues untill any character other than "y" entered.
The following odd thing happens each and every time: the first loop returns valid data, i.e., 256 values with "1,2,3,4..." pattern; the second returns "null" for the data; during the third loop the program does not return from the call to the FT_Write function at all.
Setting the timeout with FT_SetTimeouts to any value returns "IOError" from the function at third call. And when I set the incoming data size with FT_SetUSBParameters, the FT_Read returns "null" at first call.
Has anybody ever seen something similar? And how can I solve this? Any advice will be appreciated.
Regards, Kris.