This week I test the board that I design. The details of the board are explained in previous post, my first objective would be to be able to program the PIC32, confirm the osciallator is working, able to communicate with a LAN8720 to have internet connection.
To program the PIC32 of the board is fairly simple, with just a PICKIT3 (since I;m programming the board through ICSP). The hardware connection can be refer to Microchip: Programming & Diagnostic. Using PICKIT3 and MPLAB IPE -> connect board (the PIC32 chip that was used must be specified) -> browse to a hex file -> erase -> program.
The current board have 2LEDs connected to RC13 and RC14 of PIC32. To have it light up, I use harmony configurator(mhc) -> port -> set RC13 and RC14 to DIGITAL and OUTPUT -> generate code -> done. With such simple step the LED of my board has light up. Next is to make the LED blink, based on the example code from Harmony on TIMER, after some editing on the code to ensure that I am using the 24MHz oscillator that was connected to the PIC. Luckily the oscillator is working properly and I could have my LED start blinking.
refclko and lan8720a
Next is to get the PHY working with PIC32. The ethernet phy that was used on the board is LAN8720A. However this phy chip will be clock by PIC32, to achieve this is also fairly simple. In MHC-> clock -> enable REFCLKOn -> set the desired output frequency -> port -> pinout -> choose the pin that would output REFCLKO signal (in my case would be RF1) -> generate code -> done. Before that, I have the REFCLKO signal output on my LED pin, just to confirm the code is working (the result: LED light up but dimmer with REFCLKO = 50MHz). This REFCLKO will be used to clock phy chip. For the initialization of LAN8720, with MHC -> internal MAC -> ext phy -> select LAN8720. Then MHC will auto generate the intialization code for LAN8720.
I also set up TCPIP stack on PIC32 to have a simple TCP server connection. Using the initialization code that was done earlier on LAN8720 and REFCLKO adding TCPIP stack with TCP enabled on MHC. I write a very basic TCP code, which is to OPEN socket -> LISTEN -> ACCEPT -> SEND & RECEIVE. However, I keep failed during LISTEN stage, I am able to open a socket but during listen stage there would be an error whereby the port will directly close for no connection was made. Observing the behavior of the LED on RJ45 ethernet port also shows there is no connection made. After much testing I discover the problem is not with the initialization code of LAN8720, but on the clock setting of PIC32. Different clock setting on PIC32 results different behavior on the LED state of ethernet port. There are also other factor that might cause such behavior but I could not test it, for example VDDCR of lan chip should be 1.2V but not 1.5V.