@ Dave McLaughlin - I’ve tried it at 5Khz, no go.
I wonder what speed your bit banging is now running it?
It still sounds like a timing issue, especially is bit banging works.
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System;
using System.Threading;
using Toolbox.NETMF;
public static class Wiznet5100 {
/// <summary>
/// MAC Address 59-1A-4F-3A-84-A2
/// </summary>
static OutputPort reset = new OutputPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D9, true);
static OutputPort chipSelect = new OutputPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D10, true);
static OutputPort clock = new OutputPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D13, false);
static OutputPort mosi = new OutputPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D11, false);
static InputPort miso = new InputPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D12, false, Port.ResistorMode.Disabled);
static InterruptPort interrupt = new InterruptPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D8, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLevelLow);
//static SPI.Configuration config = new SPI.Configuration((Cpu.Pin)FEZCerbuino.Pin.Digital.D7,
// false, // Chip Select, active-low
// 0, // 1 millisecond setup time
// 0, // 1 millisecond hold time
// true, // Clock low on idle
// false, // Data valid on falling edge
// 5000, // 5Mhz Clock Rate
// SPI.SPI_module.SPI1);
//static SPI port = new SPI(config);
public static void Test() {
reset.Write(false);
Thread.Sleep(20);
reset.Write(true);
//Subnet Mask
BitBang(0xF00005FF); //255
BitBang(0xF00006FF); //255
BitBang(0xF00007FF); //255
BitBang(0xF0000800); //0
//MAC Address
BitBang(0xF0000959); //59
BitBang(0xF0000A1A); //1A
BitBang(0xF0000B4F); //4F
BitBang(0xF0000C3A); //3A
BitBang(0xF0000D84); //84
BitBang(0xF0000EA2); //A2
//Source IP
BitBang(0xF0000FC0); //192
BitBang(0xF00010A8 ); //168
BitBang(0xF0001102); //2
BitBang(0xF0001202); //2
//validate
Debug.Print("MAC Address: " + Tools.Dec2Hex(BitBang(0x0F000900)) + "-" + Tools.Dec2Hex(BitBang(0x0F000A00)) + "-" + Tools.Dec2Hex(BitBang(0x0F000B00))
+ "-" + Tools.Dec2Hex(BitBang(0x0F000C00)) + "-" + Tools.Dec2Hex(BitBang(0x0F000D00)) + "-" + Tools.Dec2Hex(BitBang(0x0F000E00)));
Debug.Print("Source IP : " + BitBang(0x0F000F00).ToString() + "." + BitBang(0x0F001000).ToString() + "." + BitBang(0x0F001100).ToString() + "." + BitBang(0x0F001200).ToString());
Debug.Print("Mask : " + BitBang(0x0F000500).ToString() + "." + BitBang(0x0F000600).ToString() + "." + BitBang(0x0F000700).ToString() + "." + BitBang(0x0F000800).ToString());
}
static byte BitBang(uint command) {
uint _value = 0;
chipSelect.Write(false);
for (int i = 0; i < 32; i++) {
mosi.Write(((command << i) & 0x80000000) == 0x80000000);
clock.Write(true);
_value = _value << 1 | (uint)(miso.Read() ? 1 : 0);
clock.Write(false);
}
chipSelect.Write(true);
return (byte)(_value & 0xFF);
}
}
It’s kinda weird that bit banging works where the native stuff doesn’t
EDIT: I keep forgetting to put the debug output
MAC Address: 59-1A-4F-3A-84-A2
Source IP : 192.168.2.2
Mask : 255.255.255.0
Also GHI I found a bug in your forums. If it’s within code tags, I don’t think you should be parsing for smilies.
BitBang(0xF00010A8 ); //168
I think you need to use Mode0 SPI (low on idle, valid on rising edge) or Mode 3 (high on idle, valid on rising edge). So SPI args 5 and 6 should be false,true or true,true.
This worked for me:
var spiConfig = new SPI.Configuration(
csPin, // pin to use as chip select
false, // CS active state
0, // CS setup time
0, // CS hold time
false, // clock is idle shen SCLK is in this state
true, // true=sample on rising edge; false=falling edge
5000, // Clock rate, in kHz
spiModule); // SPI module id
@ mcalsyn - That works!
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using System;
using System.Threading;
using Toolbox.NETMF;
public static class Wiznet5100 {
/// <summary>
/// MAC Address 59-1A-4F-3A-84-A2
/// </summary>
static OutputPort reset = new OutputPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D9, true);
static InterruptPort interrupt = new InterruptPort((Cpu.Pin)FEZCerbuino.Pin.Digital.D8, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeLevelLow);
static SPI.Configuration config = new SPI.Configuration((Cpu.Pin)FEZCerbuino.Pin.Digital.D10,
false, // CS active state
0, // CS setup time
0, // CS hold time
false, // clock is idle shen SCLK is in this state
true, // true=sample on rising edge; false=falling edge
5000, // Clock rate, in kHz
SPI.SPI_module.SPI1); // SPI module id
static SPI port = new SPI(config);
public static void Test() {
reset.Write(false);
Thread.Sleep(20);
reset.Write(true);
byte[] _read = new byte[4];
while (true) {
port.WriteRead(new byte[] { 0x0F, 0x00, 0x17, 0x00 }, _read);
Debug.Print("0x0017 : " + _read[3].ToString());
port.WriteRead(new byte[] { 0x0F, 0x00, 0x18, 0x00 }, _read);
Debug.Print("0x0018 : " + _read[3].ToString());
}
}
}
So therefore, it was the clock idle setting all along. What a way to spend 3 days.
EDIT: And now on to our next issue: Why is it not responding to pings