CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

USB data acquisition with Explore 16

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
geolover



Joined: 08 Feb 2011
Posts: 18

View user's profile Send private message

USB data acquisition with Explore 16
PostPosted: Fri Feb 11, 2011 2:48 pm     Reply with quote

Hello! My project involves getting data from an ADC connected to the PIC24FJ128GA010 on the explorer 16 to PC by implementing a USB CDC on the PIC18F4550 (on explorer 16 as well), a Master_Slave SPI is used for inter-PIC communication, however, upon testing, I found data coming out on putty is not what is written by PIC24FJ128GA010, here are the following code, it features a very simple function of master_slave SPI write and read:

One syndrome I found out is whenever I change the value in #use delay of PIC24FJ code, I got different data on the PC, does it suggests something wrong with PIC24FJ clock configuration?



Code:
  #include <18F4550.h>

  //configure a 20MHz crystal to operate at 48MHz
  #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
  //#fuses   USBDIV, PLL1, CPUDIV1, PROTECT, NOCPD, noBROWNOUT,HSPLL,NOWDT,nolvp, VREGEN
  #use delay(clock=48000000)

// Includes all USB code and interrupts, as well as the CDC API
#include <usb_cdc.h>

#rom int 0xf00000={1,2,3,4}

void main() {
   int16 value;
   setup_spi (SPI_SLAVE | SPI_H_TO_L | spi_ss_disabled);
   usb_cdc_init();
   usb_init();
   
   while(!usb_cdc_connected()) {}

   do {
      usb_task();
      if (usb_enumerated()) {
         printf(usb_cdc_putc, "\r\n\nData read from ADC:\r\n");              // Display contents of the first 64
      if (spi_data_is_in())
      {
    //while(!spi_data_is_in());    // wait for SPI activity from master
       // Read byre from SPI interface
       value = spi_read();
       

       // Write byte to USB
       printf(usb_cdc_putc, "%1x ",value);
      }
   }

      }while (TRUE);
   }



Code:
#INCLUDE <24FJ128GA010.h>


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOWRT                    //Program memory not write protected
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOCOE                    //Device will reset into operational mode
#FUSES ICSP2                    //ICD uses PGC2/PGD2 pins
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
#FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
#FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES PR_PLL                   //Primary Oscillator with PLL
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO                  //OSC2 is clock output
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)

#use delay(clock=32000000)


 #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>


#use rs232(UART1,baud=9600,parity=N,bits=8)


void main()
{
   

   int j;
   
   int sine_table[9]={0x10,0x09,0x11,0x22};
   setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_4 |0x0000);
   setup_spi2(SPI_SS_DISABLED);
 
 while(1)
  {
 

      for (j=0 ; j < 4 ;j++)
        {
           output_low(PIN_A0);

           spi_write(sine_table[j]);

           
           output_high(PIN_A0);
        }

       

 
   }

//   setup_wdt(WDT_ON);
//  setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);



   // TODO: USER CODE!!

}
geolover



Joined: 08 Feb 2011
Posts: 18

View user's profile Send private message

PostPosted: Tue Feb 15, 2011 4:58 am     Reply with quote

Hello! A little bit update! I find my problem, it seems there is a type mismatch: i send out binary data from PIC24FJ but print out hex number on USB, do you think that might be the cause of problem?
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Feb 15, 2011 8:48 am     Reply with quote

First, test the USB PIC > PC link by sending KNOWN data. Maybe a small table of 10 known data and confirm the PC is reading and showing them as correct.

When that happens..

test the PIC 24 to USB PIC by again, sending a table of KNOWN data.

Since we have NO idea what your PC program is doing, only you can confirm WHERE the data is being corrupted.

Also I don't have either of those PICs and don't know how you've setup the SPI physical transfer( wire length, grounds,power supplies, etc. Heck, even the MIG welder in the room two doors down could cause problems !
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group