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

PIC 16F886 SPI CONFIGURATION
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 28, 2013 10:50 pm     Reply with quote

Quote:
But when I check the SS signal with the second code its 0v (that's wrong
because last instruction is SS-HIGH).

1. Compile, load, and run the 2nd program again. Confirm that the
Slave Select line is at a low level. Then comment out all lines in main()
except for this:
Code:

void main()
{
output_high(TRF7970A_SS);
   
while(1);
}

If the program now sets TRF7970A_SS to a high level, then the problem
is likely in the other lines of main() that you commented out. Then
un-comment them one at a time, or a few at a time, and find out exactly
what line is causing the problem.

But as ckielstra says, you don't show us what is in this file,
PruebaTagEmulacion.h, so we don't know the pin definitions. What pin is
used for TRF7970A_SS ? What is in PruebaTagEmulacion.h ?

Quote:

Second Question: PIC sends the clock signal (SPI CLK - 2Mhz) only while It's sending/reading data from the SPI? I'm asking this because when I transmit only 1 byte, I cant see the SPI CLk signal on Oscilloscope, but when I transmit infinite bytes, i can see perfectly the 2Mhz Waveform.

If you just have one line that sends 1 byte, and then the program goes to
the while(1) line, you might not see it on the scope. The SCLK signal
could go by too fast, and in too short of a time for your eye to see it.
You need a logic analyzer in that case. Or, just make a test where the
line is executed continuously in a while() loop. Then you should see
something on your scope.
Armando



Joined: 02 May 2013
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Wed May 29, 2013 9:12 am     Reply with quote

Hi guys! Thanks PCM and Ckielstra for both answers.

Quote:
Second Question: PIC sends the clock signal (SPI CLK - 2Mhz) only while It's sending/reading data from the SPI? I'm asking this because when I transmit only 1 byte, I cant see the SPI CLk signal on Oscilloscope, but when I transmit infinite bytes, i can see perfectly the 2Mhz Waveform.


Yes. I tested both things: Sending a single byte and and sending infinite bytes. As PCM says, if I try to see in a scope a transmision with a single byte it will be impossible, because its too fast, but when I transmit infinite bytes, i can see perfectly the square wave in MOSI and CLK lines.

Quote:
First Question: What I'm doing wrong in the second code? its something about SPI configuration( SPI_ENABLE=0) ?


Yes. I forgot to post the "PruebaTagEmulacion.h". Check it:

Code:
#include <16F886.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC                    //Internal RC Osc
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(int=8000000)

#use FIXED_IO( B_outputs=PIN_B4 )
#define ENABLEPIN   PIN_B4
#define TRF7970A_SS   PIN_B5



Thanks in advance!
Ttelmah



Joined: 11 Mar 2010
Posts: 19549

View user's profile Send private message

PostPosted: Wed May 29, 2013 9:39 am     Reply with quote

The fact that you are programming the select pin as an input, is probably not helping......

With fixed_io selected, _you_ specify which pins are to be outputs. You are setting B5 as an output, but not B4.

In the first code, fixed_io is not specified, so the compiler does it for you.

Best Wishes
Armando



Joined: 02 May 2013
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Wed May 29, 2013 9:54 am     Reply with quote

Hi Ttelmah.

You mean I'm setting as B4 as an output, and NOT B5, right?


Regards!
ckielstra



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

View user's profile Send private message

PostPosted: Wed May 29, 2013 10:09 am     Reply with quote

ENABLEPIN and TRF7970A_SS are both outputs.
So what do you think about defining BOTH B4 and B5 as outputs?
Armando



Joined: 02 May 2013
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Wed May 29, 2013 10:16 am     Reply with quote

ENABLE PIN is just a 5V signal to power up the Slave (TRF7970A's Vin).


TRF7970A_SS is the Chip Select Signal for SPI purposes.

Both, should be defined as Outputs.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 29, 2013 10:30 am     Reply with quote

What happened was, you slipped in this line, which was not in your
previous code in this thread and you sabotaged yourself:
Quote:
#use FIXED_IO( B_outputs=PIN_B4 )
#define ENABLEPIN PIN_B4
#define TRF7970A_SS PIN_B5


Here is the last part of the .LST file. Look at what the compiler does
when you use that line:
Code:
....................    output_high(TRF7970A_SS); 
00D1:  MOVLW  EF   // Set TRISB to 0xEF
00D2:  BSF    STATUS.RP0
00D3:  MOVWF  TRISB
00D4:  BCF    STATUS.RP0
00D5:  BSF    PORTB.RB5

It sets the TRIS for PortB to 0xEF, which is 1110 1111 in binary.
Code:

TRISB settings per bit:

7654 3210
1110 1111

So it's setting pin B4 to be an output (0 = output), but pin B5 is set as an
input (1 = input). Pin B5 is your TRF7970A_SS and it must be an output.
Get rid of the fixed_io line.
Armando



Joined: 02 May 2013
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Wed May 29, 2013 12:41 pm     Reply with quote

If I delete #use FIXED_IO( B_outputs=PIN_B4 ), by default B4 and B5 will be defined as outputs? or I need to define them previously as outputs??


Also, an extra dummy question:


Why when I check the .lst file, I see this:

Code:
0034:  BSF    06.5


and not like:

Code:
00D5:  BSF   PORTB.RB5


I get 06.5 instead of PORTB.RB5. (Getting 06.5 its a little harder/confused to see the pins configuration). How I could fix that?

Thanks in advance.!
ckielstra



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

View user's profile Send private message

PostPosted: Wed May 29, 2013 12:56 pm     Reply with quote

Quote:
If I delete #use FIXED_IO( B_outputs=PIN_B4 ), by default B4 and B5 will be defined as outputs? or I need to define them previously as outputs??
What is wrong with trying and checking the resulting output? From your other question I understand you have found the list files so that can't be the problem. You have the same information as we have: the CCS manual and the generated list files.
Quick answer: no, the I/O pins are configured as inputs by default.
your program 1 is working and number 2 is not. The only difference is the fixed_io line you slipped in. Now read the manual on fixed_io again and compare the two generated list files. It should become clear to you why one version is working and the other not.

Your list file can be changed by selecting the output format to be 'symbolic' instead of the default COFF format. How to do this depends on the IDE you are using. I use MPLAB and there you configure this under the project / compiler options.
Armando



Joined: 02 May 2013
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Wed May 29, 2013 1:41 pm     Reply with quote

All right. I'm a little confused.


1) Yes, my first code works and the second code dont work.

The problem is here: #use FIXED_IO( B_outputs=PIN_B4)


As PCM said, Im setting ONLY B4 as output and not B5.


I could fix that writing:

#use FIXED_IO( B_outputs=PIN_B4,PIN_B5) or just deleting this line. Then, both lines should be work as outputs. Right?


2) I'm compiling the program directly from PCW. I'm not using an external IDLE (as MPLAB).
ckielstra



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

View user's profile Send private message

PostPosted: Wed May 29, 2013 3:36 pm     Reply with quote

Sorry, but it will help a lot when you show to put in some effort by trying things yourself. You will learn a lot from doing so and you will get the answers quicker than waiting for a response here on the forum.

Regarding question 2, I tried pointing you in the right direction but since you can't figure it out yourself here the steps for the CCS IDE:
- Open the 'Options' menu
- Click 'Project Options'
- Click 'Output Files'
- Under 'List File', select the option 'Symbolic'.
- Click 'Apply'

I still think you should try to solve question 1 yourself. You have been given all the tools and procedures to figure it out. Have you even tried reading the manual? I doubt it.

It still surprises me that you put in the FIXED_IO line without anyone telling you to do so. You have no clue as to what the line does and you have even been told by our very experienced PCM forum member to remove the line. Still, you spend a lot of time trying to keep the line in. Why???? It doesn't make any sense to me.
Armando



Joined: 02 May 2013
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Wed May 29, 2013 4:12 pm     Reply with quote

Ckielstra

Few weeks ago I started to LEARN to use both compiler tool as working with PICS, so I'm not perfect and Im still learning. Also my English is not perfect and not nearly to be, therefore, a lot of things are sp difficult to understand, and still i do the effort to understand them.

I'm not telling to you make me the work. I'm asking BECAUSE I WANNA KNOW AND UNDERSTAND WHY ITS NOT WORKING, so if I ask 1,2,3 or 4 times is because I'm not understanding you. Thats why I told you I'm confused.

Yes I READ THE MANUAL, and I never used this directive before. The pic wizard introduced this directive when i was creating and setting a new project wizard. I read several times but (thanks to my english), i'm still confused about how this directive works


I want to check the code by myself. Thats Why I asked how I could change the .lst to see more clearly the Pin's configuration.


And thanks, and as advince would be better if you could try to explain me "in a better way" than being sarcastic.
ckielstra



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

View user's profile Send private message

PostPosted: Thu May 30, 2013 12:36 am     Reply with quote

I made you angry for hoping that you started to experiment by yourself. Guess I was wrong.

We know that learning takes time. Your English is good. I'm not a native English speaker myself and I do understand you very well.

The PIC Project Wizard only puts in the fixed_io option when you make the selection to do so. In doing this you forgot to mention one output pin.

In the CCS manual, page 63, there is a section on General I/O where the 3 different I/O modes are explained:
- FAST_IO gives you complete control: the compiler is doing nothing and you as the programmer have to configure every I/O pin using the set_tris_x() functions. This is optimal for speed and memory usage.
- STANDARD_IO is the default compiler setting when you specify nothing. It is one of the CCS compiler features making your life as a programmer easier: the compiler will set the I/O ports for you, no need to set the TRIS registers yourself. The compiler is doing this on every input and output function, very flexible but so also using a few extra instructions on every I/O operation and 1 byte of RAM for every I/O port (not I/O pin).
- FIXED_IO is a bit in between the above two options: you as a programmer have to specify which pins are inputs and outputs. Then on every I/O operation the compiler will set the TRIS registers to this setting, regardless of what the I/O operation is. For example when you configure a pin as output but use an input function, then the pin will still be configured as an output. Only for special situations I can see this function being useful. The only advantage compared to STANDARD_IO is that you save 1 byte of RAM for every I/O port but it has the two disadvantages of the other two options: wasting memory space and clock cycles and you have to configure all I/O pins yourself.

Quote:
#use FIXED_IO( B_outputs=PIN_B4,PIN_B5) or just deleting this line. Then, both lines should be work as outputs. Right?
Yes, both methods will solve your problem.

Best for now is to forget about the different I/O modes. Always use the compiler default value STANDARD_IO, this will work for 95% of your programs and saves you a lot of work figuring out the I/O settings. Only when you have good reasons change to one of the other two settings.
Armando



Joined: 02 May 2013
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Thu May 30, 2013 7:58 am     Reply with quote

Ckielstra

Honestly I wasnt angry. Only I felt that you were angry because I asked over and over again the same thing. On the contrary, the more I can learn from the users of this forum and make me more independent in terms of knowledge, much better. I always have open doors to experience things for myself and learn new things. I'm sorry if someone here get mad/angry with my dummy questions, but sometimes it gets hard to understand for me.


Now, I understand you perfectly, and thanks to this explanation, I understand each directives. Indeed, perhaps if we had started here, no misunderstanding occurred.

Again, thanks for this explanation and answering the question.


Regards

Armando
Armando



Joined: 02 May 2013
Posts: 16
Location: Venezuela

View user's profile Send private message

PostPosted: Thu May 30, 2013 8:22 am     Reply with quote

I almost forgot..

Quote:
The PIC Project Wizard only puts in the fixed_io option when you make the selection to do so. In doing this you forgot to mention one output pin.


The problem was that when I was setting up the new "Project Wizard" in the SPI section I selected the box "Enable Pin = B5" and "Enable active = Low", assuming that this is the appropriate settings for the Slave Select Signal, and the data was to be transmitted when this signal would be in "Low".

Later when I was setting the "I / O Pins" options, B4 (Slave's Vin) I set it as an output, but obviously B5(For me, SS) can not be changed (the program will not let you), so never picked out B5 as a output.


Thasts why i got the code:

Code:
#use FIXED_IO( b_outputs=PIN_B4)



Regards

Armando
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
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