|
|
View previous topic :: View next topic |
Author |
Message |
lam Guest
|
Problem with ENC28J60 SPI Output |
Posted: Tue Feb 09, 2010 11:02 am |
|
|
Hi.
I have problem with reading registers value from ENC28J60.
It seems no output signal is clocking out from ENC.
Writing the registers seems to work fine.
Code to write the register:
Code: |
void WriteCONREG(int16 z, int x){
ENC_BANK(HIGH(z)); //this is 100% working bank selection code.
selectENC(); //this pulls CS low
spi_write(LOW(z)+64); // 64 = 010_aaaaa //this add WriteConfigREG command to the 5bit register adres
spi_write(x);
deselectENC(); // pullup CS high
}
|
Code to read the register (not working, it returns '0'!);
Code: |
int ReadCONREG(int16 z){
int tempvalue;
ENC_BANK(HIGH(z)); // select the bank where the desired register is.
selectENC();
spi_write(LOW(z)); // writing 000_ aaaaa 000 is ReadConfigReg command aaa is a register adres in selected bank.
tempvalue=spi_read();
deselectENC();
return tempvalue;
}
|
However when I add Pullup resistor on the SDI line I'm getting 255 (so all readed bytes are logical 1). SPI seems to work. I still don't know why no data is clocking out from ENC. |
|
|
lam Guest
|
|
Posted: Tue Feb 09, 2010 11:06 am |
|
|
Forgot to tell:
I'm using quadbuffer/line driver 74HCT125 to do the voltage level shifting from 3v3 to 5v. Buffer seems to work also. (I checked by making pullup between 74HCT input and ENC output. It makes 74HCT output logical 1 (5V ) ). |
|
|
Ttelmah Guest
|
|
Posted: Tue Feb 09, 2010 11:21 am |
|
|
I'd guess, because you are not clocking it out....
spi_read, operates in two different ways. If you call it, and you have already performed a write, it returns the value clocked 'in' during that write. So you will be receiving the value clocked in to you ,when you wrote the address to the chip. To make it generate clocks, and clock a value 'in', you have to give it an argument. So:
val=spi_read(0);
Will clock a value in from an external device.
Best Wishes |
|
|
lam Guest
|
|
Posted: Tue Feb 09, 2010 11:27 am |
|
|
Seems not to work.
According to the CCS manual spi_read() = spi_read(NULL) so its the same.
:/ still getting '0' |
|
|
lam Guest
|
|
Posted: Tue Feb 09, 2010 12:36 pm |
|
|
Quote: | Commands and data are sent to the device via the SI
pin, with data being clocked in on the rising edge of
SCK. Data is driven out by the ENC28J60 on the SO
line, on the falling edge of SCK. The CS pin must be
held low while any operation is performed and returned
high when finished. |
And my SPI config is: (I'm using this config all the time - during TX and RX to /from ENC).
Code: | SETUP_SPI(SPI_MASTER | SPI_L_TO_H | SPI_XMIT_L_TO_H |SPI_CLK_DIV_64); |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Feb 09, 2010 1:14 pm |
|
|
Quote: | According to the CCS manual spi_read() = spi_read(NULL)
|
Where does it say that in the CCS manual ? You didn't give your PIC,
so I looked in the main compiler manual and the PCD manual. There
is no statement like the above one in the spi_read() section.
It's apparent that you're trying to write your own driver for the enc28j60.
Here's the data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39662c.pdf
You didn't post the code that shows the ENC_BANK() function or macro
so I'm going to ignore it.
Your ReadCONREG() likely refers to reading a control register.
Based on the comments in your code, it appears that you're trying
to do the SPI operation shown in this diagram in the enc28j60 data sheet:
Quote: |
FIGURE 4-3: READ CONTROL REGISTER COMMAND SEQUENCE (ETH REGISTERS)
|
That diagram shows 16 clocks, with one byte being sent to the ENC
chip, and another byte being received from the ENC chip. You are
attempting to do this with these two lines of code.
Code: |
spi_write(LOW(z));
tempvalue = spi_read();
|
This won't work. Only the first line is generating the SPI clock.
You must give the spi_read() function a parameter to cause it to
generate the SPI clock. Just change the 2nd line to this:
Code: |
tempvalue = spi_read(0);
|
If it "doesn't work", it's because there is something else wrong in your
code are hardware. But the 0x00 parameter is essential. |
|
|
lam Guest
|
|
Posted: Tue Feb 09, 2010 3:43 pm |
|
|
I make another test example:
Code: |
for(;;){
selectENC();
spi_read(0x1b); // This is the EIE register - its the same adress for all banks.
value=spi_read(0x00);
deselectENC();
lcd_puti(value); //this makes string tab from int and print on the LCD.
delay_ms(1000);
clear_lcd(); //this clears LCD
}
|
And the reading was : 192, 128,0,0,0, 33, 128, 0, 0, 0, 33 , 144, 0, 0, 0 , 232
I don't know what to think. ;x |
|
|
|
|
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
|