|
|
View previous topic :: View next topic |
Author |
Message |
buzz
Joined: 12 Nov 2009 Posts: 14
|
|
Posted: Thu Nov 19, 2009 5:07 pm |
|
|
Hmm, I wasnt aware that you could remove that pin_select line and still use SS pin in code. However, still no results yet. I will set up a PIC18F4455 tomorrow and see if it works in that. |
|
|
buzz
Joined: 12 Nov 2009 Posts: 14
|
|
Posted: Sat Nov 28, 2009 8:27 pm |
|
|
I set up the connections on a PIC18F4455 proto board and I have done everything I could think of but I am still unable to make SPI connection work. I am using the code that PCM programmer had posted a couple days back and I'm getting all 00's in Serial Port Monitor. I have gone through the datasheets over and over and I dont think I am missing anything. Could setting up a basic SPI be this hard? I have spent so many days on it but have gotten no results.
Is there any other way to troubleshoot this issue? I feel doomed...
Here are some things I've tried hoping to make it work:
- connected CS pin to ground
- connected SS to ground and did SPI_SS_DISABLED to not use SS at all
- did a soft reset of W5100 by writing 0x80 to MR register (not sure if it worked since I used spi to write to the MR register)
- changed SPI modes, changed SPI timing, added delays after setting SS pin high or low, and so on...
I'm using PCH v4.066. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Nov 28, 2009 9:39 pm |
|
|
Post your current test program for the 18F4455, without all the weird
stuff, like grounding the \SS pin, etc. Just a normal SPI test program,
done to the best of your ability to match the W5100 data sheet.
The test program must be compilable, as posted.
Post the list of connections between the 18F4455 pins and the W5100.
Also note that the SDO pin and the Hardware UART's Rx pin are shared
on one pin in this PIC. I hope you're not trying to use both the hardware
SPI and hardware UART. |
|
|
buzz
Joined: 12 Nov 2009 Posts: 14
|
|
Posted: Sat Nov 28, 2009 10:17 pm |
|
|
I'm using USB instead of RS232 because of the shared UART and SPI pins. The code's basically the same as you had provided before, I made a couple of changes here and there but they didn't make any difference so now I've ended up with the same code as yours:
Code: |
#include <18F4455.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN //needed for USB functionality
#use delay(clock=48000000) //needed for USB functionality
#include <usb_cdc.h> //needed to perform USB to SERIAL functionality
#rom int 0xf00000={1,2,3,4} //needed for USB functionality
#include <usb_bootloader.h>
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
// PIC pins assigned to W5100 signals.
#define W5100_CS PIN_B2
#define W5100_RESET PIN_B3
// W5100 Commands (from W5100 data sheet).
#define W5100_WRITE_CMD 0xF0
#define W5100_READ_CMD 0x0F
// W5100 Register addresses (from W5100 data sheet).
#define W5100_MR_REG 0x0000
#define W5100_GAR0_REG 0x0001
#define W5100_GAR1_REG 0x0002
#define W5100_GAR2_REG 0x0003
#define W5100_GAR3_REG 0x0004
// etc.
// This routine writes 1 byte of data to a W5100 register
// at the specified register address.
void w5100_write_reg(int16 addr, int8 data)
{
output_low(W5100_CS); delay_us(30);
spi_write(W5100_WRITE_CMD);
spi_write((addr&0xFF00)>> 8); // Send address msb
spi_write((addr&0x00FF)); // Send address lsb
spi_write((data&0x00FF)); // Write data to W5100
output_high(W5100_CS);delay_us(30);
}
// This routine reads 1 byte of data from a W5100 register
// at the specified register address.
int8 w5100_read_reg(int16 addr)
{
int8 retval;
output_low(W5100_CS);delay_us(30);
spi_write(W5100_READ_CMD);
spi_write((addr&0xFF00) >> 8); // Send address msb
spi_write((addr&0x00FF)); // Send address lsb
retval = spi_read(0); // Read data from W5100
output_high(W5100_CS);delay_us(30);
return(retval);
}
int8 gar0, gar1, gar2, gar3;
unsigned int8 status;
void main()
{
usb_cdc_init(); //configure the CDC driver
usb_init(); //start up the USB driver
// Initialize the W5100 chip select signal to the deselected state.
output_high(W5100_CS); delay_us(20);
// Reset the W5100 chip and then wait for the time
// specified in the W5100 data sheet.
output_low(W5100_RESET);
delay_us(10); // Minimum reset pulse width is 2 us
output_high(W5100_RESET);
delay_ms(25); // Maximum Plock delay time is 10 ms
// Setup the PIC's SPI module to work with the W5100 chip.
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_16);
// Writing MR register for software reset, doesnt make any difference
//! w5100_write_reg(W5100_MR_REG, 0x80);
//! do {
//! status = w5100_read_reg(W5100_MR_REG);
//! } while (status & 0x80);
// See if we can write to the Gateway Address Registers
// (GAR0-GAR3). Just fill them with some test data.
w5100_write_reg(W5100_GAR0_REG, 0x12);
w5100_write_reg(W5100_GAR1_REG, 0x34);
w5100_write_reg(W5100_GAR2_REG, 0x56);
w5100_write_reg(W5100_GAR3_REG, 0x78);
// Now read back the GAR registers.
gar0 = w5100_read_reg(W5100_GAR0_REG);
gar1 = w5100_read_reg(W5100_GAR1_REG);
gar2 = w5100_read_reg(W5100_GAR2_REG);
gar3 = w5100_read_reg(W5100_GAR3_REG);
// Display the results. Look on the terminal window
// to see if it's correct. Should be: 12 34 56 78
while(TRUE)
{
while(usb_cdc_connected())
{
usb_task();
// Send to Serial port monitor
printf(usb_cdc_putc,"Result: %X %X %X %X \n\r", gar0, gar1, gar2, gar3);
delay_ms(2000);
}
}
}
|
Here are the pin configs:
Code: |
PIC Wiznet
#34 J2:3
#33 J1:2
#26 J1:1
#35(B2) J2:4
#36(B3) J2:2
J1:12 and J2:1 to 3.3V
J1:11 and J1:20 to Gnd
|
I'm powering up Wiznet module with PIC Kit2 for 3.3V, the proto board is powered by its adapter and both proto and wiznet have a common ground. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Nov 28, 2009 11:19 pm |
|
|
Quote: | I'm powering up Wiznet module with PIC Kit2 for 3.3V, |
Is the PIC's Vdd voltage on the 18F4455 board also at 3.3 volts ?
Quote: | printf(usb_cdc_putc,"Result: %X %X %X %X \n\r", gar0, gar1, gar2, gar3); |
Have you proven that the CDC communication works ? Can you put
values into gar0-3, and se values other than 0x00 on your PC ? |
|
|
buzz
Joined: 12 Nov 2009 Posts: 14
|
|
Posted: Sat Nov 28, 2009 11:22 pm |
|
|
Nope, the PIC's mounted on a prototype board and am using its power adapter to power it up. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Nov 28, 2009 11:23 pm |
|
|
But what is the voltage on the Vdd pins of the 18F4455 ? Measure it. |
|
|
buzz
Joined: 12 Nov 2009 Posts: 14
|
|
Posted: Sat Nov 28, 2009 11:36 pm |
|
|
Vdd shows 5V on a multimeter. And yes, cdc is working, I tried putting some random value on gar0 and it displayed the value. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 29, 2009 12:05 am |
|
|
Quote: |
But what is the voltage on the Vdd pins of the 18F4455 ? Measure it.
Vdd shows 5V on a multimeter
|
There is a problem with this.
The SDI pin on the PIC is a "Schmitt Trigger" input pin, according to
the 18F4455 data sheet. The high level input voltage is specified at
.8 x Vdd, which is .8 x 5v = 4v in your case. But the MISO pin on the
Wiz812MJ puts out a 3.3v CMOS level signal. That's not high enough to
meet the requirements of the PIC's SDI pin. That's probably the major
reason why your communications don't work.
For the signals going from the PIC to the Wiz board, there is no problem
with the levels, because the Wiz board data sheet says the inputs are
5v tolerant.
You need to add a level converter to the 18F4455 board on the SDI pin.
You need to convert from 3.3v CMOS to 5v CMOS levels. A 74HCTxx-
series gate would work. This logic family can run from 5v, but has TTL
input levels, so it will work with 3.3v CMOS signals on the inputs. It will
put out 5v CMOS levels on the outputs. You need a non-inverting gate,
such as a 74HCT125 (connect the enable pin to ground). Or some other
gate can be used, such as a 74HCT08. Any other logic family that can
run with a 5v Vdd voltage, but has "TTL" compatible inputs will work.
Another possibility is to make your 18F4455 board run at 3.3v, but that
might not be easy to do. It might be easier just to add the level
converter on the SDI pin. |
|
|
buzz
Joined: 12 Nov 2009 Posts: 14
|
|
Posted: Sun Nov 29, 2009 12:24 am |
|
|
Hmm, never thought of it from that angle. I will try making a buffer myself and see if that helps, will let you know. Thanks for all your input, I really appreciate it. |
|
|
buzz
Joined: 12 Nov 2009 Posts: 14
|
|
Posted: Mon Dec 07, 2009 3:09 pm |
|
|
wow, after almost a month i finally have SPI working on the pic18. phewww.... the problem was really simple. I was using a hard-drive IDE cable to connect the wiznet to my breadboard coz it matched perfectly with wiznet's pins, but what i wasnt aware of was that Pins 1 and 2 on the IDE were INTERNALLY SHORTED!. So no wonder i wasnt getting the right output!! i then made my own IDC connector and connected the 74hct125 line driver and its now working exactly as it should!!!
thanks again PCM programmer for all ur help, it was invaluable for a newbie like me. |
|
|
influx
Joined: 15 Feb 2012 Posts: 1
|
|
Posted: Fri Feb 24, 2012 2:41 pm |
|
|
Hi |
|
|
|
|
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
|