View previous topic :: View next topic |
Author |
Message |
sajsaj220
Joined: 01 Nov 2019 Posts: 1
|
Why can't use the MSSP2 module for the SPI protocol |
Posted: Sat Nov 02, 2019 12:03 am |
|
|
Hi all,
I am using compiler CCS (v5.008) and MCU PIC18F46k22(has 2 MSSP module) , to display text in P10-DMD using MSSP2 module of the MCU.
---My target to use MSSP1 for hardware I2C (for RTC clock) and MSSP2 for hardware SPI (to display clock data in DMD).-----
For that, FIRST going to setup Hardware SPI for DMD with MSSP2 Module,
All things are going correct if MSSP1 is used with the code below SPI configuration---
Code: | #use SPI(SPI1, MODE = 0, BITS = 8, STREAM = P10_Panel_Driver) |
But if MSSP2 is configured with below, then the MSSP2 for SPI is not working, even SCK2 pin is not responding.
Code: | #use SPI(SPI2, MODE = 0, BITS = 8, STREAM = P10_Panel_Driver) |
Is this enough for SPI2 to work or anything else that I am missing?
Anyone can help me?
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Nov 02, 2019 12:08 am |
|
|
Both port have analog functions that have priority over their use
for SPI. The SPI1 port only has ADC pins and these are normally
turned off automatically. The SPI2 port has comparator functions on
the same pins, and this peripheral needs to be turned off. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Nov 02, 2019 1:11 am |
|
|
What PIC pin are you looking at with your oscilloscope to see the SCK2 signal ?
Post your code that sends a byte using the SPI2 module. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sat Nov 02, 2019 4:30 am |
|
|
couple of comments.
1) 5v008 is very early and may have a few 'bugs' in it...
2) It's always good to add 'Baud=rate' to the options. If NOT specified, the SPI will be clocked at the fastest rate possible. Some SPI devices won't work at very fast clock rates. If you add the option, you can SEE what the rate is.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sun Nov 03, 2019 3:31 am |
|
|
I've just checked, and your compiler does seem to be doing everything OK.
Code: |
#include <18F46K22.h> //
#fuses INTRC_IO //Internal RC Osc, no CLKOUT
#fuses NOWDT, BROWNOUT, PUT, NOPBADEN, NOHFOFST
#fuses NOMCLR
#use delay(internal=4MHz) //
#use SPI(SPI2, MODE = 0, BITS = 8, STREAM = P10_Panel_Driver)
void main() {
setup_comparator(NC_NC_NC_NC);
setup_adc(NO_ANALOGS);
while(true){ //Basic SPI test
spi_xfer(P10_Panel_Driver, 0x55);
delay_us(50);
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 03, 2019 3:51 am |
|
|
I looked at the .LST file a while ago and saw the same thing.
That's why I asked him what pin he was looking at when he
said it doesn't put out an SCK2 signal. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Sun Nov 03, 2019 5:45 am |
|
|
Almost sounds like a a 'solder whisker' might be causing the problem ?
Perhaps cut small program to 'toggle' the I/O pin and use scope or LED to see if that works.
Jay |
|
|
|