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 support@ccsinfo.com

adc setup change SPI function in pic24

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



Joined: 02 May 2012
Posts: 18

View user's profile Send private message

adc setup change SPI function in pic24
PostPosted: Thu Nov 29, 2012 10:31 am     Reply with quote

Hi,
I have found no sense in ADC setup. In same configuration it blocks SPI communication.
Some idea?
Thanks
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Nov 29, 2012 4:48 pm     Reply with quote

We are not mind readers. We need three things to start:

Your compiler version.

ALL the initialization code you used from the 1st (device) line to the start of main.

If it is not shown in the above we need the model of the PIC.
_________________
Google and Forum Search are some of your best tools!!!!
ck



Joined: 02 May 2012
Posts: 18

View user's profile Send private message

PostPosted: Fri Nov 30, 2012 2:34 am     Reply with quote

Hi dyeatman,
Thanks for reply. I'm using PIC24HJ256GP610.
Here are my fuses:
Code:

#DEVICE ADC=12

#fuses NOWDT   //No Watch Dog Timer
#fuses NOWRTB   //Boot block not write protected
#fuses NOBSS   //No boot segment
#fuses NOPROTECT  //Code Protected form reads
#fuses NOWRT   //Program memory not write protected
#fuses PR_PLL   //Primary Oscillator with PLL
#fuses NOCKSFSM   //Clock Switching disabled
#fuses NOOSCIO   //OSC2 is clock output
#fuses HS      //Primary oscillator HS
#fuses WINDIS   //WD in non-windows mode
#fuses WPRES128
#fuses WPOSTS16
#fuses PUT128   //No Power on Reset Timer value
#fuses IESO   //Internal external switch Over mode disabked //NOIESO
#fuses NORSS   //No secure segment RAM
#fuses NOSSS   //No secure segment
#fuses NOWRTSS   //Secure segment not write protected
#fuses NORBS   //No Boot Ram defined
#fuses NODEBUG   //No debug mode
#fuses NOJTAG   //JTAG DISABLED
#fuses ICSP2   //ICD2 uses pin2

#use delay(clock=80M)



and this is first code blocks that initialized the PIC:

Code:

   
RCON=0b0000000001000000;
CLKDIV=0;
PLLFBD=0x1E;
   
//watch dog OFF
setup_wdt(WDT_OFF);

#use fast_io(A)
set_tris_a(0b0111000011000000);
output_a(0);
   
#use fast_io(B)
set_tris_b(0b0000110011111111);
output_b(0);

#use fast_io(C)
set_tris_c(0);
output_c(0);

#use fast_io(D)
set_tris_d(0b1000000000000000);
output_d(0b0000000000111111);

#use fast_io(E)
set_tris_e(0b0000000000011111);
output_e(0);

#use fast_io(F)
set_tris_f(0b0000000010110001);
output_f(0);

set_pullup(PIN_F1);      // pull-up su TX

#use fast_io(G)
set_tris_g(0);
output_g(0);

setup_adc_ports(NO_ANALOGS);
setup_adc_ports2(NO_ANALOGS);

setup_compare(1,COMPARE_OFF);   
setup_compare(2,COMPARE_OFF);
setup_compare(3,COMPARE_OFF);
setup_compare(4,COMPARE_OFF);
setup_compare(5,COMPARE_OFF);
setup_compare(6,COMPARE_OFF);
setup_compare(7,COMPARE_OFF);
setup_compare(8,COMPARE_OFF);

 
//SPI 1

setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_1);
   


If I compile it with 4.134 it does't work (SPI Problem due to NO_ANALOGS port).
If I compile it with 4.104 it works ok.

You can say me: "Who cares, use 4.104 version".
I reply: "I can not do it, because i will use this code with a CANbootloader, and in CCS 4.104 doesn't work the IVT remap, but in 4.134 it's okay for remap."

So now I'm blocking!
ck



Joined: 02 May 2012
Posts: 18

View user's profile Send private message

PostPosted: Fri Nov 30, 2012 7:13 am     Reply with quote

How can is possible that with one versione of Compiler SPI works, Timers not at all, with other SPI doesn't send DATA, but timers work good. How many bugs there are in PCD??
How can a user pay for loose his time?
Ttelmah



Joined: 11 Mar 2010
Posts: 19368

View user's profile Send private message

PostPosted: Sat Dec 01, 2012 2:29 am     Reply with quote

Seriously, just look at the assembler generated.
Now, the three instructions involved, only code as under ten lines of assembler, and if they talk to different registers, then you know what is wrong.
Don't have 4.134 handy, but compiling the code sections on 4.104, gives:
Code:

....................    setup_adc_ports(NO_ANALOGS);
0024E:  SETM    32C
00250:  SETM    32A
....................    setup_adc_ports2(NO_ANALOGS);
00252:  SETM    36C
00254:  SETM    36A

....................    setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_1);
00266:  BCLR.B  242.7
00268:  BCLR.B  240.6
0026A:  MOV     #13F,W4
0026C:  MOV     W4,242
0026E:  BSET.B  241.7


and compiling on 4.137, gives:
Code:

....................    setup_adc_ports(NO_ANALOGS);
00256:  SETM    32C
00258:  SETM    32A
....................    setup_adc_ports2(NO_ANALOGS);
0025A:  SETM    36C
0025C:  SETM    36A

....................    setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_1);
0026E:  BCLR.B  241.7
00270:  BCLR.B  240.6
00272:  MOV     #1FF,W4
00274:  MOV     W4,242
00276:  BSET.B  241.7

Which actually disables/enables the SPI (241.7, is the SPIEN bit), and re-configures. Which is what you are asking it to do. The 4.104 code doesn't disable the peripheral first (incorrect), but won't cause any problem as such.
The lines for the setup ADC, do nothing except set all the pins as digital (correct), so the problem is somewhere else, if 4.134 generates the same code. So just look. What does it generate?.
However, notice the two different values sent to register 242. 13F, and 1FF. The setup in the later compiler, is setting the CKP bit, and appears to do it whatever you select:
Code:

....................    setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_1|SPI_SCK_IDLE_LOW);
0026E:  BCLR.B  241.7
00270:  BCLR.B  240.6
00272:  MOV     #1FF,W4
00274:  MOV     W4,242
00276:  BSET.B  241.7

....................    setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_1|SPI_SCK_IDLE_HIGH);
0026E:  BCLR.B  241.7
00270:  BCLR.B  240.6
00272:  MOV     #1FF,W4
00274:  MOV     W4,242
00276:  BSET.B  241.7

Duh.....

I'd suspect this is the actual error, stopping the SPI from working, which for some reason, the ADC setup in your case just 'reveals'....

In fact the setup ADC lines are 'redundant'. NO_ANALOGS is the default setting, and the compiler has:
Code:

.................... void main(void) {
*
00200:  BSET.B  81.7
00202:  SETM    32C
00204:  SETM    32A
00206:  SETM    36C
00208:  SETM    36A

At the start of the main, setting the ports to digital, so you don't need these lines at all. So remove them.

Also, the setup you are using for the SPI is invalid. Look at the data sheet. Note the line:
"2: Do not set both Primary and Secondary prescalers to a value of 1:1."

You are doing this.

Best Wishes
ck



Joined: 02 May 2012
Posts: 18

View user's profile Send private message

PostPosted: Mon Dec 03, 2012 11:20 am     Reply with quote

Hi Ttelmah,
thanks for reply. I have saw in simulation what setup_spi does in both compiler version. I have decided to configure SPI's register manually with this code:
Code:

SPI1CON1:0x013E;
SPI1CON2:0;
SPI1STAT=0x8000;

and it works.
Analog part does not influence SPI's functions.

you have right do not set both prescaler 1:1 but not in all case: It depend of clock source. in 70243b.pdf is better explained.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Dec 04, 2012 4:30 am     Reply with quote

Has someone sent a bug report to CCS?
In the last week we've seen three new releases... Had they known this problem they could have squeezed it in.
Ttelmah



Joined: 11 Mar 2010
Posts: 19368

View user's profile Send private message

PostPosted: Tue Dec 04, 2012 4:58 am     Reply with quote

ck wrote:
Hi Ttelmah,
thanks for reply. I have saw in simulation what setup_spi does in both compiler version. I have decided to configure SPI's register manually with this code:
Code:

SPI1CON1:0x013E;
SPI1CON2:0;
SPI1STAT=0x8000;

and it works.
Analog part does not influence SPI's functions.

you have right do not set both prescaler 1:1 but not in all case: It depend of clock source. in 70243b.pdf is better explained.


Yes, it depends on Fcy, but at your CPU clock of 80M, it is illegal.....
Fcy, is Fosc/2.

Best Wishes
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