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

HW SPI and LCD Not working

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



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

HW SPI and LCD Not working
PostPosted: Sat Jun 27, 2020 1:31 pm     Reply with quote

Using a LCD with ST7565R Controller and bit bang the SPI everything works fine.
I'd prefer to use hardware SPI but can't make it work.
The display is a write only device so DI from the device is not needed.
The help file mentions:
"pins must be specified with DI, DO, CLK or SPIx"

What am I doing wrong ? Thanks in advance for any help.

Code:

#include <18F47K42.h> 

// compiler V5.093

#FUSES NOWDT
#FUSES NOPRLOCK1WAY

#use delay(clock=48000000,crystal=12000000)
 
#pin_select SCK1=PIN_B4
#pin_select SDO1=PIN_B5
#use spi (MASTER, SPI1, MODE=0, BITS=8, IDLE=0, FORCE_HW, STREAM=LCD)

/////////////////////////
// does not work
void SPIout(int8 out)
{
   spi_xfer(LCD, out ); // also tried spi_write() also did not work.
}


////////////////////////
// Bit Bang works
void SPIout(char out)
{
  char mask;

  mask = 0x80;
  do{
   
     output_low(PIN_B4);
     
     if(out & mask)
     {
        output_high(PIN_B5);
     }
     else
     {
       output_low(PIN_B5);
     }
     
     output_high(PIN_B4);

     mask >>= 1; // next bit

   }while(mask > 0);
}
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

PostPosted: Sat Jun 27, 2020 2:30 pm     Reply with quote

Try a couple of things:

1. Set the input signal to the same pin as the output signal
2. Set the baud in the #use spi() directive to a slower speed than max. Maybe you are going too fast.
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Thanks
PostPosted: Sat Jun 27, 2020 4:29 pm     Reply with quote

jeremiah wrote:
Try a couple of things:

1. Set the input signal to the same pin as the output signal
2. Set the baud in the #use spi() directive to a slower speed than max. Maybe you are going too fast.


1. Help file says: "SPI cannot use the same pins for DI and DO."

2. Display is rated for 20MHz. Should be fast enough. I'll try reducing Baud and post results tomorrow.
jeremiah



Joined: 20 Jul 2010
Posts: 1354

View user's profile Send private message

Re: Thanks
PostPosted: Sat Jun 27, 2020 4:40 pm     Reply with quote

soonc wrote:
jeremiah wrote:
Try a couple of things:

1. Set the input signal to the same pin as the output signal
2. Set the baud in the #use spi() directive to a slower speed than max. Maybe you are going too fast.


1. Help file says: "SPI cannot use the same pins for DI and DO."

2. Display is rated for 20MHz. Should be fast enough. I'll try reducing Baud and post results tomorrow.


1. That's probably if you are specifying them in the #use spi(), which you should not be for a hardware SPI. Just try setting the pin_selects for both to the same pin. If it doesn't work, then at least you tried. Obviously, if the LCD did output data, you couldn't make them the same (you would have dueling drivers for the I/O), but in this case you don't have a physical I/O line from the LCD going to the DI line.

2. That's fine, but consider that software SPI is way slower than hardware SPI. So in situations where I find software SPI works and hardware SPI doesn't, it is often times the speed. Again, just give it a whirl (datasheets can have errors, parts can have errata, parts can be counterfit or mislabeled...seen all of that). If it doesn't help, then at least you tried.

All else fails, send an email to CCS support and ask them what the recommended setup is for this situation. Maybe they have one in mind that isn't obvious from the options in the help.
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Re: Thanks
PostPosted: Sat Jun 27, 2020 7:23 pm     Reply with quote

jeremiah wrote:
soonc wrote:
jeremiah wrote:
Try a couple of things:

1. Set the input signal to the same pin as the output signal
2. Set the baud in the #use spi() directive to a slower speed than max. Maybe you are going too fast.


1. Help file says: "SPI cannot use the same pins for DI and DO."

2. Display is rated for 20MHz. Should be fast enough. I'll try reducing Baud and post results tomorrow.


1. That's probably if you are specifying them in the #use spi(), which you should not be for a hardware SPI. Just try setting the pin_selects for both to the same pin. If it doesn't work, then at least you tried. Obviously, if the LCD did output data, you couldn't make them the same (you would have dueling drivers for the I/O), but in this case you don't have a physical I/O line from the LCD going to the DI line.

2. That's fine, but consider that software SPI is way slower than hardware SPI. So in situations where I find software SPI works and hardware SPI doesn't, it is often times the speed. Again, just give it a whirl (datasheets can have errors, parts can have errata, parts can be counterfit or mislabeled...seen all of that). If it doesn't help, then at least you tried.

All else fails, send an email to CCS support and ask them what the recommended setup is for this situation. Maybe they have one in mind that isn't obvious from the options in the help.


Thanks. You nailed it...
It did compile with same pin for DO and DI.
Next I reduced Baud to 400,000 and it worked.
The I increased the Baud number until it stopped at 8MBaud.
I got a little more curious and put the scope on the display CE line.
This code simply transfers 1024 bytes to the display each time it writes anything.
BitBang took 40mS to transfer 1024 bytes.
I ended up using 3.5MBaud and it now does the same transfer in 17mS.
Although everything compiled with higher Baud numbers 17mS was the fastest transfer time.
So I'll back off until the transfer is close to 20mS which is a nice 50 frames per second.
Although that sounds wonderful I just noticed the LCD does not keep up with the animation so I'll most likely have to slow it some more.

Anyway great help thanks I appreciate it.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Sun Jun 28, 2020 1:47 am     Reply with quote

I don't see you turning off slew rate control.
The pins on this PIC have hardware slew rate control on their outputs.
This is why there is a warning in the data sheet for the fastest SPI rates:
Quote:

the slew rate control must be disabled on the clock and data pins


This may be why your faster attempts were failing....

set_slow_slew_b(FALSE);

Finding that the LCD can't actually keep up, is common....
However normally the key is to send the data nice and quickly, and then
use the extra time to do other things. Very Happy
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

Nice Thanks
PostPosted: Sun Jun 28, 2020 3:48 pm     Reply with quote

Ttelmah wrote:
I don't see you turning off slew rate control.
The pins on this PIC have hardware slew rate control on their outputs.
This is why there is a warning in the data sheet for the fastest SPI rates:
Quote:

the slew rate control must be disabled on the clock and data pins


This may be why your faster attempts were failing....

set_slow_slew_b(FALSE);

Finding that the LCD can't actually keep up, is common....
However normally the key is to send the data nice and quickly, and then
use the extra time to do other things. Very Happy


I had no idea such a thing was available...!
I found anything over 9MBaud did not improve the speed.
That got the transfer speed down to 13.94mS for 1024 Bytes.

Thanks great help ....
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