View previous topic :: View next topic |
Author |
Message |
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
spi_read clock |
Posted: Fri Jan 14, 2005 9:46 am |
|
|
Hello,
I'm using CCS 3.28 (PCM 3.150). My pic is 16F873A.
I'm using spi_write succesfully with it and I can see the clock. But when I want to read data, I can see any clock : spi_read...
Is it normal ???
Thanks for your reading
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Jan 14, 2005 10:54 am |
|
|
Is your system configured as master or slave? In a slave system you won't see the clock.
For a spi-master, remember SPI is a two-way bus where you are always sending and transmitting simultaneously so spi_read requires a parameter. Depending on whether you want a constant high or low level on the data-output use either spi_read(0x00) or spi_read(0xff). |
|
|
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
|
Posted: Mon Jan 17, 2005 2:12 am |
|
|
My PIC is MASTER.
What do you mean by "Depending on whether you want a constant high or low level on the data-output use either spi_read(0x00) or spi_read(0xff)" ?
Thanks for your support |
|
|
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
|
Posted: Mon Jan 17, 2005 3:10 am |
|
|
Well I have tested with spi_read(0xFF) and the clock I obtain is only 4 bits long. What shall I do in order to have 8 bits clock ???
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jan 17, 2005 5:30 pm |
|
|
Quote: | Well I have tested with spi_read(0xFF) and the clock I obtain is only 4 bits long. | This sounds very strange, I never heard of similar problems before.
Are you using the hardware SPI unit?
Can you post a (small) example program?
Quote: | What do you mean by "Depending on whether you want a constant high or low level on the data-output use either spi_read(0x00) or spi_read(0xff)" ? | I didn't express myself very clear. Using the spi_read() function you will output data as well. Depending on the connected device you have to decide what data you want transmit while reading the bus. |
|
|
YulL
Joined: 29 Sep 2004 Posts: 39 Location: Paris (France)
|
|
Posted: Tue Jan 18, 2005 2:19 am |
|
|
PIC is master, the other component is
Init of the PIC :
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4);
I send : spi_write(0x7f); and there is no problem
00AE: MOVF 13,W
00AF: MOVLW 7F
00B0: MOVWF 13
00B1: BSF 03.5
00B2: BTFSS 14.0
00B3: GOTO 0B2
spi_read(0) or spi_read(0xFF) have a 4 bits clock :
00D2: MOVF 13,W
00D3: CLRF 13
00D4: BSF 03.5
00D5: BTFSS 14.0
00D6: GOTO 0D5
I have succesfully tested the SPI between 2 PIC with the same function. But it should came from the component. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jan 18, 2005 3:23 am |
|
|
It looks like you have a hardware problem, try a 1k Ohm series resistor in the clock line. Also removing the probe might solve the problem.
See this thread http://forum.microchip.com/tm.asp?m=67287 |
|
|
Guest Guest
|
|
Posted: Mon Mar 14, 2005 5:39 pm |
|
|
ckielstra wrote: | It looks like you have a hardware problem, try a 1k Ohm series resistor in the clock line. Also removing the probe might solve the problem.
See this thread http://forum.microchip.com/tm.asp?m=67287 |
I just wanted to say thank you for the solution. The problem is the impedance of the probe (or connection to the other device). I found that a 1K-ohm resistor is a little too much, and that 100 ohms is much cleaner of a match (you should see nice square pulses on your probe even using a non-active probe).
Thanks again. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Mar 15, 2005 1:48 am |
|
|
Quote: | I just wanted to say thank you for the solution. | You are welcome.
Thanks for telling us the problem is solved. |
|
|
Guest
|
|
Posted: Sat Nov 05, 2005 10:53 am |
|
|
YulL wrote: | PIC is master, the other component is
Init of the PIC :
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_CLK_DIV_4);
I send : spi_write(0x7f); and there is no problem
00AE: MOVF 13,W
00AF: MOVLW 7F
00B0: MOVWF 13
00B1: BSF 03.5
00B2: BTFSS 14.0
00B3: GOTO 0B2
spi_read(0) or spi_read(0xFF) have a 4 bits clock :
00D2: MOVF 13,W
00D3: CLRF 13
00D4: BSF 03.5
00D5: BTFSS 14.0
00D6: GOTO 0D5
I have succesfully tested the SPI between 2 PIC with the same function. But it should came from the component. |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Nov 06, 2005 5:45 pm |
|
|
Dear Guest,
First some general remarks
1) The formatting of your question is very difficult to read.
2) Please register yourself to this forum. Besides being polite this gives you the option to edit your messages and fix possible errors in your post.....
3) When posting a question alway mention:
- The processor you are using.
- Your compiler version.
For your problem:
- Have you tried to insert a 100 Ohm resistor in the clock line as suggested? |
|
|
|