|
|
View previous topic :: View next topic |
Author |
Message |
Bill Turnip Guest
|
SPI_WRITE timing |
Posted: Tue Jun 24, 2003 8:12 pm |
|
|
Hello -
I've hooked up a MAX7219 to a PIC16F877 in order to output the PIC data to a 4-digit LED display. The MAX7219 uses SPI protocol and 3 pins: /CS (chip select), CLK (clock), and SDI (serial data in). Drop the /CS pin low, send the MSB of the data to the PIC's SDO (serial data out) pin, and when the CLK goes high, the serial data on SDO is shuttled into the MAX's SDI pin. When I use a "bit bang" approach and toggle all the lines "manually" (and sequentially), everything works fine. However, when I use the built-in CCS function "SPI-WRITE" it doesn't work.
Using an oscilloscope, I found that when you use the SPI_WRITE function, both the CLK and the SDO pins change state simultaneosuly. On the other hand, for all SPI devices I have used in the past, the data needs to be "setup" first (and be stable) before the clock toggles from Low to High (or low to high depending upon the specific device). If the clock and data change too close together in time, the clock may be trying to toggle in data that is not yet stable - you know, metastability issues related to inadequate setup times may occur.
Any ideas on how to work around this? (I know, "bang" the bits out like I am doing already...) I just wanted to see if I could get the SPI functions to work....
Thanks very much,
Bill
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515541 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: SPI_WRITE timing |
Posted: Tue Jun 24, 2003 10:01 pm |
|
|
:= Using an oscilloscope, I found that when you use the SPI_WRITE function, both the CLK and the SDO pins change state simultaneously.
---------------------------------------------------
To set the proper SPI mode for your chip, see this post by
Charlie U, while referring to Figure 9-2 (SPI Mode Timing)
in the 16F877 data sheet. Charlie U has defined some constants
that allow you to use the CCS functions, and setup the SPI
mode that you need.
<a href="http://www.pic-c.com/forum/general/posts/9317.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/9317.html</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515544 |
|
|
Forest Guest
|
Re: SPI_WRITE timing |
Posted: Wed Jun 25, 2003 2:41 am |
|
|
:=Hello -
:= I've hooked up a MAX7219 to a PIC16F877 in order to output the PIC data to a 4-digit LED display. The MAX7219 uses SPI protocol and 3 pins: /CS (chip select), CLK (clock), and SDI (serial data in). Drop the /CS pin low, send the MSB of the data to the PIC's SDO (serial data out) pin, and when the CLK goes high, the serial data on SDO is shuttled into the MAX's SDI pin. When I use a "bit bang" approach and toggle all the lines "manually" (and sequentially), everything works fine. However, when I use the built-in CCS function "SPI-WRITE" it doesn't work.
:= Using an oscilloscope, I found that when you use the SPI_WRITE function, both the CLK and the SDO pins change state simultaneosuly. On the other hand, for all SPI devices I have used in the past, the data needs to be "setup" first (and be stable) before the clock toggles from Low to High (or low to high depending upon the specific device). If the clock and data change too close together in time, the clock may be trying to toggle in data that is not yet stable - you know, metastability issues related to inadequate setup times may occur.
:=
:= Any ideas on how to work around this? (I know, "bang" the bits out like I am doing already...) I just wanted to see if I could get the SPI functions to work....
:=
:=Thanks very much,
:=Bill
Bill
I have an 877 connected to a Microchip 25AA320 (external EEPROM) and seem to have no problems, the max shouldn't be that different (in setup). Check what mode the Max7219 operates in but I would think it was mode 0,0.
I use the following setup and it seems to work.
setup_adc_ports(NO_ANALOGS);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H |SPI_XMIT_L_TO_H|SPI_CLK_DIV_4|SPI_SAMPLE_AT_END);
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515549 |
|
|
Bill Turnip Guest
|
Re: SPI_WRITE timing - OK |
Posted: Wed Jun 25, 2003 7:28 am |
|
|
Guys -
I simply added the following to the SPI_SETUP function:
"SPI_XMIT_L_TO_H" and now my clocks are going from Low to High in the middle of the SDO bit cell as needed. This option isn't in my ancient manual...
Thanks!
Bill
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515558 |
|
|
Forest Guest
|
Re: SPI_WRITE timing - OK |
Posted: Thu Jun 26, 2003 6:09 pm |
|
|
:=Guys -
:=
:= I simply added the following to the SPI_SETUP function:
:="SPI_XMIT_L_TO_H" and now my clocks are going from Low to High in the middle of the SDO bit cell as needed. This option isn't in my ancient manual...
:=
:=Thanks!
:=Bill
You are quite right, even the latest manual on the web does not detail it. Have a look at the device file for the 16F877 - this is where I found it, the define (#define SPI_XMIT_L_TO_H 0x4000) gives u a clue as to how it works.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515588 |
|
|
|
|
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
|