View previous topic :: View next topic |
Author |
Message |
buster22098
Joined: 29 Sep 2009 Posts: 8
|
SPI() |
Posted: Tue Sep 29, 2009 5:34 pm |
|
|
I have a VFD display and want to try to write some code for it using SPI.
I am new to SPI but understand the principle that it is (essentially) a RS232 in software but am curious as to how to set this up on my PIC using CCS. I have always used LCDs using the lcd.c file (or flex_lcd.c) but now want to try this method.
According to this ( http://www.ccsinfo.com/content.php?page=spi ) page I can set up the SPI using the following;
Code: | #use SPI (DO = PIN_B0, DI = PIN_B1, CLK = PIN_B2, baud = 100000, BITS = 8, LSB_FIRST, SAMPLE_RISE, stream = SPI_PORT0) |
I assume the following;
DO is the pin for data out from the master
DI is the pin for data in if the PIC was the slave
CLK is the clock
baud is for....
BITS is for....
LSB_FIRST is so the LSB is sent first; the opposite of MSB_FIRST
SAMPLE_RISE is for......
Stream is for.....
How does the above method differ from;
Code: | setup_spi(SPI_SLAVE | SPI_MODE_1_1 | SPI_SS_DISABLED); |
and what are the option using this method?
I assume the CS pin can be any pin I want seeing as it just has to be high or low to initiate or end a transfer of data??
spi_write(0xEE); is the code required to send a bit of data (in hex)
The data sheet for the VFD is here ( http://www.okisemi.com/en/dbps_data/_material_/eng/semicon/display/datasheet/images_c_display/ml9208.pdf ). If anyone has used this VFD (or a similar one) and has had success I would be very grateful to peruse the code you use.
Thanks in advance!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 29, 2009 6:00 pm |
|
|
You posted a data sheet for the controller. Post the manufacturer and
part number of the actual display. Post a link to the website for the
display. |
|
|
buster22098
Joined: 29 Sep 2009 Posts: 8
|
|
Posted: Tue Sep 29, 2009 6:40 pm |
|
|
I am unsure of the manufacturer. It was liberated from a PACE Microtechnology set top box
It has 8 unique segments with 5x7 dots in each.
Does the VFD manufacturer matter to get it to work?
My friend, who obtained it for me, has had it working but he used the hi-tech compiler, not ccs |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 29, 2009 7:05 pm |
|
|
Get his source code and translate it to CCS. |
|
|
buster22098
Joined: 29 Sep 2009 Posts: 8
|
|
Posted: Tue Sep 29, 2009 7:18 pm |
|
|
I have his source code and have converted it to CCS.
What I am unsure of is how to set up SPI using CCS.
Code: | void initialise_VFD(void)
{
Delay10KTCYx(256);
// Command 1
ClearCSSWSPI();
putcSWSPI(0x86); // Selecting com1 - com9
SetCSSWSPI();
Delay10KTCYx(1);
// Command 2
ClearCSSWSPI();
putcSWSPI(0xEA); // Selecting duty cycle 15/16
SetCSSWSPI();
Delay10KTCYx(1);
// Command 3
ClearCSSWSPI();
putcSWSPI(0x08); // Setting DCRAM address com1
// Command 4
putcSWSPI(0x08); // Writing nothing to com1
// Command 5
putcSWSPI(0x08); // Writing nothing to com2
// Command 6
putcSWSPI(0x08); // Writing nothing to com3
// Command 7
putcSWSPI(0x08); // Writing nothing to com4
// Command 8
putcSWSPI(0x08); // Writing nothing to com5
// Command 9
putcSWSPI(0x08); // Writing nothing to com6
// Command 10
putcSWSPI(0x08); // Writing nothing to com7
// Command 11
putcSWSPI(0x08); // Writing nothing to com8
SetCSSWSPI();
Delay10KTCYx(1);
// Command 12
ClearCSSWSPI();
putcSWSPI(0x0E); // Normal Display clearing all low and all high
SetCSSWSPI();
Delay10KTCYx(1);
// Command 13
ClearCSSWSPI();
putcSWSPI(0x0E); // setting P2 General Output Port Setting
SetCSSWSPI();
Delay10KTCYx(1);
// Command 14 is not written to VFD
Delay10TCYx(8);
// Command 15
ClearCSSWSPI();
putcSWSPI(0xC2); // setting P1 and P2 General Output Port Setting
SetCSSWSPI();
Delay10KTCYx(1);
// Write to screen
ClearCSSWSPI();
putcSWSPI(0x08); // Select DCRAM address com1
putcSWSPI(0x08); // ' '
putcSWSPI(0x08); // ' '
putcSWSPI(0x08); // ' '
putcSWSPI(0x22); // 'T'
putcSWSPI(0x22); // 'T'
putcSWSPI(0x08); // ' '
putcSWSPI(0x08); // ' '
putcSWSPI(0x08); // ' '
SetCSSWSPI();
Delay10TCYx(8);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 29, 2009 7:45 pm |
|
|
Post his SPI setup routine. |
|
|
buster22098
Joined: 29 Sep 2009 Posts: 8
|
|
Posted: Tue Sep 29, 2009 8:12 pm |
|
|
PCM programmer wrote: | Post his SPI setup routine. |
All he sent me was the above so I've sent him an e-mail. Will post the results. I've also asked hime to verify the pins on the board also |
|
|
buster22098
Joined: 29 Sep 2009 Posts: 8
|
Re: SPI() |
Posted: Tue Sep 29, 2009 10:20 pm |
|
|
buster22098 wrote: |
According to this ( http://www.ccsinfo.com/content.php?page=spi ) page I can set up the SPI using the following;
Code: | #use SPI (DO = PIN_B0, DI = PIN_B1, CLK = PIN_B2, baud = 100000, BITS = 8, LSB_FIRST, SAMPLE_RISE, stream = SPI_PORT0) |
How does the above method differ from;
Code: | setup_spi(SPI_SLAVE | SPI_MODE_1_1 | SPI_SS_DISABLED); |
|
I'd appreciate if someone could clarify my original question |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 29, 2009 10:42 pm |
|
|
The options are listed in the CCS manual:
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
The #use spi() statement allows you to do software SPI without writing
code to manually transfer the bits. You can just specify the parameters
and use the xfer_spi() function to send/receive the bits.
#use spi() provides a higher level interface than the traditional CCS
functions. It's more complex. More of the aspects of the SPI setup and
data transfer are hidden from you. There is more possibility for error in
choosing the correct parameters. In earlier versions of the compiler
it sometimes defaulted to non-standard modes if you didn't specify
everything. That may have been fixed by now.
For people who have used the traditional method for hardware SPI,
I think we find it easier to keep on doing so, instead of trying the
#use spi() method. Probably the same is true for software SPI.
There is a large amount of sample code using for(;;) loops to send
the data. So there doesn't appear to be much need to switch to
the new method. |
|
|
buster22098
Joined: 29 Sep 2009 Posts: 8
|
|
Posted: Wed Sep 30, 2009 8:15 am |
|
|
So, (if I read it write), they are mutually exclusive options?
Using #use spi hides a lot of the setup parameters from the user where setup_spi() doesn't.
How do you specify the data in, data out, and clk pins using setup_spi()? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Sep 30, 2009 11:49 am |
|
|
Quote: |
How do you specify the data in, data out, and clk pins using setup_spi()?
|
Setup_spi uses the hardware SPI pins on the PIC, which are labeled
SCK, SDO, SDI (and \SS) in the pin diagram in the PIC data sheet.
If your PIC doesn't have hardware SPI, then you can't use setup_spi().
Quote: | So, (if I read it write), they are mutually exclusive options? |
See the explanations of spi_write() and spi_read() in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=35442
To find a lot of sample code for setup_spi, go to the forum's search page
http://www.ccsinfo.com/forum/search.php
In the top box, enter:
Quote: | setup_spi spi_write |
In the Author box, enter:
Select the Tickbox for:
Quote: | x Search for all terms |
|
|
|
buster22098
Joined: 29 Sep 2009 Posts: 8
|
|
Posted: Wed Sep 30, 2009 12:11 pm |
|
|
Thank you very much, this has immensely cleared up how to use spi() with ccs!
I have had some luck with using #use spi() and using xfer_spi() to send data to my VFD and will also try the other method. |
|
|
|