![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
geolover
Joined: 08 Feb 2011 Posts: 18
|
Use I/O pin to trigger event |
Posted: Thu Mar 24, 2011 9:28 am |
|
|
In my circuit, an ADC's /DRDY pin will pulse low when data is ready to retrieve and then returns high on the falling edge of the first subsequent SCLK, if data is not retrieved (SCLK held low), this pin will pulse high just before next conversion data is ready.
I am using PCD compiler v4.117, in my programme, i use set_tris_a(0x10) to set Pin RA4 to input state, which is connected to the /DRDY pin of ADC.
Part of my code is below: when DRDY goes low, while((DRDY!=0)); become false, and spi2 will try to read from the ADC, generating the serial clock and
read data in, however, upon compiling, I found that the compiler warned me that the condition while((DRDY!=0)); is always true, and when I powered up the devices and connect serial clock of PIC which is connecting to serial clock of the ADC, I found out there is no serial clock on the oscilloscope....
Could anyone tell me why?
Code: | #include <24FJ128GA010.h>
#include "stdio.h"
#include "string.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 NOIESO //Internal External Switch Over mode disabled
#FUSES PR //Primary Oscillator
//#FUSES PR_PLL //Primary Oscillator with PLL
#FUSES CKSNOFSM //Clock Switching is enabled, fail Safe clock monitor is disabled
#FUSES NOOSCIO //OSC2 is clock output
#FUSES XT
#use delay(clock=32000000)
#use rs232(UART1,baud=9600,parity=N,bits=8)
#define AD_SYNC PIN_A0
#define DRDY PIN_A4
#define DAC1_CS PIN_A7
#byte SPI2BUF = 0x0268
#bit SPIRBF2 =0x0260.0
#bit frmen1 = 0x0244.15
#bit spifsd1= 0x0244.14
#bit spifpol1 = 0x0244.13
#bit spifsd1 = 0x0244.2
#bit spife1 = 0x0244.1
#bit spisidl2 = 0x0260.13
#bit frmen2 = 0x0264.15
#bit spifsd2 = 0x0264.14
#bit spifpol2= 0x0264.13
#bit spife2 = 0x0264.2
#bit spiben = 0x0264.1
#bit TRISF7 = 0x02DE.7
const sine1[480]={random 480 points 16-bit numbers....};
void main()
{
delay_ms(1);
unsigned char colon= ':';
unsigned char h='h';
unsigned char i='i';
unsigned char t='t';
unsigned char c='c';
int16 j,k;
int8 ad_samples1[480],ad_samples2[480],ad_samples3[480];
// int8 ad_samples1,ad_samples2,ad_samples3;
// TRISF7 = 1;
// spisidl2 =0;
// frmen2=1;
// spifsd2=1;
// spifpol2=1;
// spife2=0;
// spiben=0;
set_tris_a(0x10); //A0,A7 output while A4 is input(/DRDY)
setup_spi2(spi_master | spi_l_to_h | spi_clk_div_4);
setup_spi(spi_master | spi_l_to_h | spi_clk_div_4);
output_low(AD_SYNC);
delay_us(2);
output_high(AD_SYNC);
while(1)
{
for (j=0;j<480;j++)
{
output_low(DAC1_CS);
// writeSPI2(sine[j]);
spi_write2(make8(sine1[j],1)); //get msb from i and write to spi2
// delay_us(100);
spi_write2(make8(sine1[j],0)); // lsb same stuff
// delay_us(100);
output_high(DAC1_CS);
while((DRDY!=0));
ad_samples1[j]=spi_read2(0x00);
ad_samples2[j]=spi_read2(0x00);
ad_samples3[j]=spi_read2(0X00);
}
output_low(PIN_A7);
for(k=0;k<480;k++)
{
spi_write(h);
delay_us(100);
spi_write(i);
delay_us(100);
spi_write(t);
delay_us(100);
spi_write(colon);
delay_us(100);
spi_write(make8(sine1[k],1));
delay_us(100);
spi_write(make8(sine1[k],0));
delay_us(100);
spi_write(ad_samples1[k]);//write 8-bit data into spi
delay_us(100);
spi_write(ad_samples2[k]);
delay_us(100);
spi_write(ad_samples3[k]);
delay_us(100);
}
output_high(PIN_A7);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9173 Location: Greensville,Ontario
|
|
Posted: Thu Mar 24, 2011 11:25 am |
|
|
IS pin RA4 open collector ? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 24, 2011 1:07 pm |
|
|
Quote: | I found that the compiler warned me that the condition while((DRDY!=0)); is always true |
The compiler is correct. In the line below, you have DRDY defined
as a pin number:
Code: | #define DRDY PIN_A4 |
Look in the file below, and see what the definition of 'PIN_A4' is:
If you need more help, see this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=45012&start=1 |
|
![](templates/subSilver/images/spacer.gif) |
geolover
Joined: 08 Feb 2011 Posts: 18
|
|
Posted: Thu Mar 24, 2011 1:47 pm |
|
|
PCM programmer wrote: | Quote: | I found that the compiler warned me that the condition while((DRDY!=0)); is always true |
The compiler is correct. In the line below, you have DRDY defined
as a pin number:
Code: | #define DRDY PIN_A4 |
Look in the file below, and see what the definition of 'PIN_A4' is:
If you need more help, see this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=45012&start=1 |
I solved this problem by manually read RD7's PORT register, but thanks, now I know the approriate way to do it ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|