这是我第一次自己做的关于强大的Arduino和WIZnet WIZ810MJ的组合。下面就是作品~
我从ebay买了一个卡,自己做的焊接,我并很擅长这个,因为毕竟这是我第一次做,不过还好,最终我完成了!!
这就是我经过几个小时焊接的结果~~
很好,我可以连接Arduino了!!!
我按照下面的教程:
http://code.rancidbacon.com/LearningAboutArduinoWIZ810MJ
经过模块的调试,我终于可以ping了
我用一个交叉以太网电缆直接连接到电脑上,因为是通过wifi连接的,所以连接以太网是免费的。。。
下面是用来成功ping 的代码(Arduino 代码):
*
Code to test wiznet WIZ810MJ module
See:
Current features:
* Read register/address values
* Write register/address values
* Configure networking to enable ping
* Terrible hacked-together code
License:
LGPL
(Although note spi_transfer comes from the Playground originally.)
*/
// Define SPI-related pins
#define PIN_DATA_OUT 11 // MOSI (Master Out / Slave In)
#define PIN_DATA_IN 12 // MISO (Master In / Slave Out)
#define PIN_SPI_CLOCK 13 // SCK (Serial Clock)
#define PIN_SLAVE_SELECT 10 // SS (Slave Select)
#define PIN_RESET 9 // WIZnet module /RESET
#define WIZNET_OPCODE_READ 0x0F
#define WIZNET_OPCODE_WRITE 0xF0
#define DUMMY_DATA 0xFF
void setup () {
Serial.begin(9600);
Serial.println("Setup enter...");
Serial.print("SPCR: "); Serial.println(SPCR, BIN);
// Configure SPI
// Configure I/O pins
pinMode(PIN_DATA_OUT, OUTPUT);
pinMode(PIN_DATA_IN, INPUT);
pinMode(PIN_SPI_CLOCK, OUTPUT);
pinMode(PIN_SLAVE_SELECT, OUTPUT);
digitalWrite(PIN_SLAVE_SELECT, HIGH); // Disable slave
// Configure SPI Control Register (SPCR) (All values initially 0)
// Bit Description
// 7 SPI Interrupt Enable -- disable (SPIE --> 0)
// 6 SPI Enable -- enable (SPE --> 1)
// 5 Data Order -- MSB 1st (DORD --> 0) (Slave specific)
// 4 Master/Slave Select -- master (MSTR --> 1)
// 3 Clock Polarity -- (CPOL --> 0) (Slave specific) ("Mode")
// 2 Clock Phase -- (CPHA --> 0) (Slave specific)
// 1 SPI Clock Rate Select 1 -- } (SPR1 --> 0)
// 0 SPI Clock Rate Select 0 -- } fOSC/4 (SPR0 --> 0) ("Fastest" but see SPI2X in SPSR)
SPCR = (1< <
Serial.print("SPCR: "); Serial.println(SPCR, BIN);
// Clear previous data and status (TODO: Determine if necessary/better way.)
// (Based on Playground SPI example.)
byte dummy;
dummy = SPSR;
dummy = SPDR;
delay(10);
// Serial.println((1 <<>
// Serial.print("IODIR response: ");
// iodirVal = getRegister(deviceOpcodeRead, REG_IODIR);
// Serial.println(iodirVal, BIN);
// setRegister(deviceOpcodeWrite, REG_IODIR, newVal);
Serial.println("Triggering reset...");
pinMode(PIN_RESET, OUTPUT);
digitalWrite(PIN_RESET, HIGH); // no reset
delay(10); // Pretty arbitrary length
digitalWrite(PIN_RESET, LOW); // reset
delay(10);
digitalWrite(PIN_RESET, HIGH); // no reset
delay(10);
Serial.println("Reset triggered...");
// Attempt read
Serial.println("Read attempt...");
// digitalWrite(PIN_SLAVE_SELECT, LOW); // Enable slave
// RTR Retry Time-value Register
Serial.print("Read 0x0017: "); Serial.println(readAddressValue(0x00, 0x17), HEX);
Serial.print("Read 0x0018: "); Serial.println(readAddressValue(0x00, 0x18), HEX);
Serial.println("Read attempt end...");
Serial.println("Write attempt start...");
Serial.print("Initial read 0x0001: "); Serial.println(readAddressValue(0x00, 0x01), HEX);
writeAddressValue(0x00, 0x01, 0xC0);
Serial.print("Post-write read 0x0001: "); Serial.println(readAddressValue(0x00, 0x01), HEX);
Serial.println("Write attempt end...");
Serial.println("Configure device...");
// default gateway
writeAddressValue(0x00, 0x01, 0xC0);
writeAddressValue(0x00, 0x02, 0xA8);
writeAddressValue(0x00, 0x03, 0x02);
writeAddressValue(0x00, 0x04, 0x65);
// subnet mask
writeAddressValue(0x00, 0x05, 0xFF);
writeAddressValue(0x00, 0x06, 0xFF);
writeAddressValue(0x00, 0x07, 0xFF);
writeAddressValue(0x00, 0x08, 0x00);
// source hardware address (MAC?)
writeAddressValue(0x00, 0x09, 0x00);
writeAddressValue(0x00, 0x0A, 0xDE);
writeAddressValue(0x00, 0x0B, 0xAD);
writeAddressValue(0x00, 0x0C, 0xBE);
writeAddressValue(0x00, 0x0D, 0xEF);
writeAddressValue(0x00, 0x0E, 0x00);
// source ip address
writeAddressValue(0x00, 0x0F, 0xC0);
writeAddressValue(0x00, 0x10, 0xA8);
writeAddressValue(0x00, 0x11, 0x02);
writeAddressValue(0x00, 0x12, 0x69);
Serial.println("End configure device...");
Serial.println("Setup exit...");
}
byte readAddressValue(byte addressHiByte, byte addressLowByte) {
// TODO: use a word for the address instead
byte data = 0x00;
digitalWrite(PIN_SLAVE_SELECT, LOW); // Enable slave
// TODO: Check response values? e.g. 0x00, 0x01, 0x02
spi_transfer(WIZNET_OPCODE_READ);
spi_transfer(addressHiByte);
spi_transfer(addressLowByte);
data = spi_transfer(DUMMY_DATA);
digitalWrite(PIN_SLAVE_SELECT, HIGH); // Disable slave
return data;
}
void writeAddressValue(byte addressHiByte, byte addressLowByte, byte targetValue) {
// TODO: use a word for the address instead
digitalWrite(PIN_SLAVE_SELECT, LOW); // Enable slave
// TODO: Check response values? e.g. 0x00, 0x01, 0x02
spi_transfer(WIZNET_OPCODE_WRITE);
spi_transfer(addressHiByte);
spi_transfer(addressLowByte);
spi_transfer(targetValue);
digitalWrite(PIN_SLAVE_SELECT, HIGH); // Disable slave
}
// From Playground
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<
{
};
return SPDR; // return the received byte
}
void loop() {
}
更多关于WIZnet WIZ810MJ 的详细信息,请参考:http://www.wiznettechnology.cn/
如果您有什么疑问请直接留言也可以登录WIZnet的官网:http://www.wiznettechnology.cn/
或者来信:Tel: 86-10-84539974(转166),QQ:2464237212,邮箱:wiznetbj@wiznettechnology.com,联系人:Lily Zhang,谢谢!
我从ebay买了一个卡,自己做的焊接,我并很擅长这个,因为毕竟这是我第一次做,不过还好,最终我完成了!!
这就是我经过几个小时焊接的结果~~
很好,我可以连接Arduino了!!!
我按照下面的教程:
http://code.rancidbacon.com/LearningAboutArduinoWIZ8
经过模块的调试,我终于可以ping了
我用一个交叉以太网电缆直接连接到电脑上,因为是通过wifi连接的,所以连接以太网是免费的。。。
下面是用来成功ping 的代码(Arduino 代码):
*
Code to test wiznet WIZ810MJ module
See:
Current features:
* Read register/address values
* Write register/address values
* Configure networking to enable ping
* Terrible hacked-together code
License:
LGPL
(Although note spi_transfer comes from the Playground originally.)
*/
// Define SPI-related pins
#define PIN_DATA_OUT 11 // MOSI (Master Out / Slave In)
#define PIN_DATA_IN 12 // MISO (Master In / Slave Out)
#define PIN_SPI_CLOCK 13 // SCK (Serial Clock)
#define PIN_SLAVE_SELECT 10 // SS (Slave Select)
#define PIN_RESET 9 // WIZnet module /RESET
#define WIZNET_OPCODE_READ 0x0F
#define WIZNET_OPCODE_WRITE 0xF0
#define DUMMY_DATA 0xFF
void setup () {
Serial.begin(9600);
Serial.println("Setup enter...");
Serial.print("SPCR: "); Serial.println(SPCR, BIN);
// Configure SPI
// Configure I/O pins
pinMode(PIN_DATA_OUT, OUTPUT);
pinMode(PIN_DATA_IN, INPUT);
pinMode(PIN_SPI_CLOCK, OUTPUT);
pinMode(PIN_SLAVE_SELECT, OUTPUT);
digitalWrite(PIN_SLAVE_SELECT, HIGH); // Disable slave
// Configure SPI Control Register (SPCR) (All values initially 0)
// Bit Description
// 7 SPI Interrupt Enable -- disable (SPIE --> 0)
// 6 SPI Enable -- enable (SPE --> 1)
// 5 Data Order -- MSB 1st (DORD --> 0) (Slave specific)
// 4 Master/Slave Select -- master (MSTR --> 1)
// 3 Clock Polarity -- (CPOL --> 0) (Slave specific) ("Mode")
// 2 Clock Phase -- (CPHA --> 0) (Slave specific)
// 1 SPI Clock Rate Select 1 -- } (SPR1 --> 0)
// 0 SPI Clock Rate Select 0 -- } fOSC/4 (SPR0 --> 0) ("Fastest" but see SPI2X in SPSR)
SPCR = (1<
Serial.print("SPCR: "); Serial.println(SPCR, BIN);
// Clear previous data and status (TODO: Determine if necessary/better way.)
// (Based on Playground SPI example.)
byte dummy;
dummy = SPSR;
dummy = SPDR;
delay(10);
// Serial.println((1 <<>
// Serial.print("IODIR response: ");
// iodirVal = getRegister(deviceOpcodeRead, REG_IODIR);
// Serial.println(iodirVal, BIN);
// setRegister(deviceOpcodeWrite, REG_IODIR, newVal);
Serial.println("Triggering reset...");
pinMode(PIN_RESET, OUTPUT);
digitalWrite(PIN_RESET, HIGH); // no reset
delay(10); // Pretty arbitrary length
digitalWrite(PIN_RESET, LOW); // reset
delay(10);
digitalWrite(PIN_RESET, HIGH); // no reset
delay(10);
Serial.println("Reset triggered...");
// Attempt read
Serial.println("Read attempt...");
// digitalWrite(PIN_SLAVE_SELECT, LOW); // Enable slave
// RTR Retry Time-value Register
Serial.print("Read 0x0017: "); Serial.println(readAddressValue(0x00, 0x17), HEX);
Serial.print("Read 0x0018: "); Serial.println(readAddressValue(0x00, 0x18), HEX);
Serial.println("Read attempt end...");
Serial.println("Write attempt start...");
Serial.print("Initial read 0x0001: "); Serial.println(readAddressValue(0x00, 0x01), HEX);
writeAddressValue(0x00, 0x01, 0xC0);
Serial.print("Post-write read 0x0001: "); Serial.println(readAddressValue(0x00, 0x01), HEX);
Serial.println("Write attempt end...");
Serial.println("Configure device...");
// default gateway
writeAddressValue(0x00, 0x01, 0xC0);
writeAddressValue(0x00, 0x02, 0xA8);
writeAddressValue(0x00, 0x03, 0x02);
writeAddressValue(0x00, 0x04, 0x65);
// subnet mask
writeAddressValue(0x00, 0x05, 0xFF);
writeAddressValue(0x00, 0x06, 0xFF);
writeAddressValue(0x00, 0x07, 0xFF);
writeAddressValue(0x00, 0x08, 0x00);
// source hardware address (MAC?)
writeAddressValue(0x00, 0x09, 0x00);
writeAddressValue(0x00, 0x0A, 0xDE);
writeAddressValue(0x00, 0x0B, 0xAD);
writeAddressValue(0x00, 0x0C, 0xBE);
writeAddressValue(0x00, 0x0D, 0xEF);
writeAddressValue(0x00, 0x0E, 0x00);
// source ip address
writeAddressValue(0x00, 0x0F, 0xC0);
writeAddressValue(0x00, 0x10, 0xA8);
writeAddressValue(0x00, 0x11, 0x02);
writeAddressValue(0x00, 0x12, 0x69);
Serial.println("End configure device...");
Serial.println("Setup exit...");
}
byte readAddressValue(byte addressHiByte, byte addressLowByte) {
// TODO: use a word for the address instead
byte data = 0x00;
digitalWrite(PIN_SLAVE_SELECT, LOW); // Enable slave
// TODO: Check response values? e.g. 0x00, 0x01, 0x02
spi_transfer(WIZNET_OPCODE_READ);
spi_transfer(addressHiByte);
spi_transfer(addressLowByte);
data = spi_transfer(DUMMY_DATA);
digitalWrite(PIN_SLAVE_SELECT, HIGH); // Disable slave
return data;
}
void writeAddressValue(byte addressHiByte, byte addressLowByte, byte targetValue) {
// TODO: use a word for the address instead
digitalWrite(PIN_SLAVE_SELECT, LOW); // Enable slave
// TODO: Check response values? e.g. 0x00, 0x01, 0x02
spi_transfer(WIZNET_OPCODE_WRITE);
spi_transfer(addressHiByte);
spi_transfer(addressLowByte);
spi_transfer(targetValue);
digitalWrite(PIN_SLAVE_SELECT, HIGH); // Disable slave
}
// From Playground
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<
{
};
return SPDR; // return the received byte
}
void loop() {
}
更多关于WIZnet WIZ810MJ 的详细信息,请参考:http://www.wiznettechnology.cn/
如果您有什么疑问请直接留言也可以登录WIZnet的官网:http://www.wiznettechnology.cn/
没有评论:
发表评论