Hi
This simple code works with no interrupt and porta as out and port b as in adresse is 64 write and 65 read (all low)
setRegister(register , value);
byte readRegister(register);
  | ||||||||||||||
The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
k_madsen's ContentThere have been 3 items by k_madsen (Search limited from 14-May 23) #59459 Mcp23s17 (SPI) with NP2+Posted by k_madsen on 30 July 2014 - 08:13 AM in Netduino Plus 2 (and Netduino Plus 1) Hi This simple code works with no interrupt and porta as out and port b as in adresse is 64 write and 65 read (all low)
setRegister(register , value); byte readRegister(register);
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
//using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
namespace addonkm
{
class MCP23S17
{
const byte IODIRA = 0x00; //iodirektion register 1 = in 0 = out default = 1
const byte IODIRB = 0x10;
const byte IPOLA = 0x01; // invert pin om port 1 = invert default = 0
const byte IPOLB = 0x11;
const byte GPINTNA = 0x02; //int on change 1 = aktiv default = 0
const byte GPINTNB = 0x12;
const byte DEFVALA = 0x03; //def comp reg on chage ved int on def change der genereres et int hvis 1 bit ikke har samme polaritet som dette register hvis enablet(intcon)
const byte DEFVALB = 0x13;
const byte INTCONA = 0x04; // int control register 1 = compare with DEFVALA 0 = compare with last pin value
const byte INTCONB = 0x14;
const byte IOCON = 0x05; // io expander config register bit 7 = bank mirror seqop disslw haen odr intpol 0
const byte GPPUA = 0x06; // pullup ressistors
const byte GPPUB = 0x16;
const byte INTFA = 0x07; //int flag register 1 = pin that coursed the interrupt
const byte INTFB = 0x17;
const byte INTCAPA = 0x08; // interrupt captured value
const byte INTCAPB = 0x18;
const byte GPIOA = 0x09; //Port register read port value read
const byte GPIOB = 0x19;
const byte OLATA = 0x0a; // output latch register write
const byte OLATB = 0x1a;
private byte adresse;
private byte adrread;
static SPI.Configuration spiNormal = new SPI.Configuration(Pins.GPIO_PIN_D7,
false,
0,
0,
false,
true,
10000,
SPI_Devices.SPI1
);
SPI SPIBus = new SPI(spiNormal);
public void setRegister(byte register, byte value)
{
byte[] buff = new byte[3];
buff[0] = adresse;
buff[1] = register;
buff[2] = value;
SPIBus.Write(buff);
}
public byte readRegister(byte register)
{
byte[] buff = new byte[3];
byte[] readbuff = new byte[3];
buff[0] = adrread;
buff[1] = register;
buff[2] = 0; //spi dummy
SPIBus.WriteRead(buff, readbuff);
return readbuff[2];
}
private MCP23S17()
{
}
public MCP23S17(byte adress)
{
adresse = (byte)(adress << 1);
adrread = (byte)(adresse | 1);
//saet port a til out og port b ind
setRegister(IODIRA, 0); // alle bit out
setRegister(GPPUA , 0xff); // alle pull op trans on
setRegister(GPPUB, 0xff);
setRegister(IOCON, 0xe2);
}
}
}
#59397 Control 80V DC Motor/Bulb Using Netduino 2Posted by k_madsen on 25 July 2014 - 08:28 PM in General Discussion G320X Digital Servo Drive this is hit all your needs inclusive with your incuranse.
regards Kim #59385 Control 80V DC Motor/Bulb Using Netduino 2Posted by k_madsen on 25 July 2014 - 08:43 AM in General Discussion
go to your local elektrician an get som relayes,
| ||||||||||||||
|
||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | ||||||||||||||