Thanks for the reply Kelvin.
Not worried because the code compiles. I just wanted to bring it to your notice.
I wrote a sketch to connect to the 5500 but it didn’t work. Code below
[code]
/* Dated: 15th April
*
* A sketch to read the PHYCFGR Register using SPI in Arduino.
* Module is RTL8720 (BW16)
* Ameba Arduino SDK - 3.1.7
*
* Demo Video at my YT Channel @aurangzebhaque2973
* For any questions please comment in YT, OR send me whatsapp message @ +923020050060, with your query.
*
*/
#include <SPI.h>
#include "definitions.h"
//#include "read.h"
//#include "write.h"
#define SPI_HAS_EXTENDED_CS_PIN_HANDLING 1
SPISettings my_spi(40000000, MSBFIRST, 0);// SPI setup, 40 MHz clock speed
#define SPI_MODE 'M'
uint16_t address = 0x0000;
byte control = 0b00000100;
byte reg_Data = 0;
void setup() {
Serial.begin(115200);
Serial.println("VERSIONR Register Test!");
SPI.begin(PA15);
delay(1);
}
void loop() {
address = VERSIONR;
write_reg(address, control, reg_Data);
read_reg(address, control, reg_Data);
Serial.print("VERSIONR Address -- ");
Serial.println (VERSIONR, HEX);
Serial.print ("CONTROL -- ");
Serial.println (control);
Serial.print ("VERSIONR -- ");
Serial.println (reg_Data);
Serial.println (); Serial.println ();
delay(1000);
}
//==================================
byte read_reg(uint16_t address, byte control,byte reg_Data){
SPISettings my_spi(40000000, MSBFIRST, 0);// SPI setup, 40 MHz clock speed
byte Acontrol;
if ((control & 0b00000100) != 0b00000000){
Acontrol = control | 0b00000000;
}
digitalWrite(PA15, HIGH);
SPI.beginTransaction(PA15,my_spi);
SPI.transfer16(address);
SPI.transfer(Acontrol);
reg_Data = SPI.transfer(0);
delay(1);
SPI.endTransaction();
digitalWrite(PA15, LOW);
reg_Data = 255;
return(reg_Data);
}
//============================
void write_reg(uint16_t address, byte control, byte reg_Data){
SPISettings my_spi(40000000, MSBFIRST, 0);// SPI setup, 40 MHz clock speed
byte Acontrol;
if ((control & 0b00000100) != 0b00000000){
Acontrol = (control | 0b00000100);
}
digitalWrite(PA15, HIGH);
SPI.beginTransaction(PA15,my_spi);
SPI.transfer16(address);
SPI.transfer(Acontrol);
SPI.transfer(0);
delay(1);
SPI.endTransaction();
digitalWrite(PA15, LOW);
return;
}
//=============================================
[/code]
The following code shows how the write() function is implemented in Ladyada Ethernet2 library.
uint8_t W5500Class::write(uint16_t _addr, uint8_t _cb, uint8_t _data)
{
SPI.beginTransaction(wiznet_SPI_settings);
setSS();
SPI.transfer(_addr >> 8);
SPI.transfer(_addr & 0xFF);
SPI.transfer(_cb);
SPI.transfer(_data);
resetSS();
SPI.endTransaction();
return 1;
}
My code uses two functions read_reg() and write_reg to read and write data onto the 5500,as follows:
a) The first two transfer() statements are replaced by SPI.transfer16() in my code.
b) The control and data bytes transfer statements in my code are the same as in Ethernet2.
c) For the resetSS() in Ethernet2 lib, I have used " digitalWrite(PA15, LOW)". THIS MAYBE AN ISSUE.
However the code works only up to the setup() function. The Serial.print() statements, inside the loop() function, do not work as there is no output. It seems that the read_reg() and write_reg() funtions aren’t working as these are meant to.
I shall continue to debug the code and shall report result. If everything fails I’ll break down the 16 bit in MSB and LSB and use transfer() as has been done in Ethernet2…
Your quick replies are very encouraging for which many many thanks.
Regards and good wishes from Pakistan.
azhaque