Faken,
The UBW32 is a very good way to go, from what I can tell of your requirements. It will support exactly what you need, as long as you're OK with 3.3V I/O (some are 5V tolerant, but not all.) It is inexpensive ($40) and is very easy to talk to using any language that can support serial ports (which is pretty much all of them - Basic, C, C#, Processing, etc.)
You can use any of the 76 I/O pins as inputs or outputs. The stock firmware as shipped will allow you to do what you want to do, no programming required on the embedded side. Getting that data up to the PC over USB (at only 10Hz) will be no problem. Getting outputs to go at 1KHz will probably work just fine as well.
If you have any questions, please let me know. I'm happy to help you out.
*Brian Schmalz
UBW32 creator
There are several I/O connection features that are in use by different PICs. The PIC that you're using has the following features (as copied from the heading of the relevant chapters of the data sheet):
11.0 I/O PORTS
Each port has six standard registers for its operation. These
registers are:
TRISx registers (data direction)
PORTx registers (reads the levels on the pins of the device)
LATx registers (output latch)
INLVLx (input level control)
ODCONx registers (open-drain)
SLRCONx registers (slew rate
Some ports may have one or more of the following additional registers.
These registers are:
ANSELx (analog select)
WPUx (weak pull-up)
Ports that support analog inputs have an associated ANSELx register.
When an ANSEL bit is set, the digital input buffer associated with
that bit is disabled. Disabling the input buffer prevents analog
signal levels on the pin between a logic high and low from causing
excessive current in the logic input circuitry.
11.3.5 ANALOG CONTROL
The ANSELB register (Register 11-12) is used to configure the Input
mode of an I/O pin to analog. Setting the appropriate ANSELB bit high
will cause al digital reads on the pin to be read as ‘0’ and allow
analog functions on the pin to operate correctly. The state of the
ANSELB bits has no effect on digital out put functions. A pin with
TRIS clear and ANSELB set wil still operate as a digital output, but
the Input mode will be analog. This can cause unexpected behavior when
exe- cuting read-modify-write instructions on the affected port.
Note: The ANSELB bits default to the Analog mode after Reset. To use
any pins as digital general purpose or peripheral inputs, the
corresponding ANSEL bits must be initialized to ‘0’ by user software.
12.0 PERIPHERAL PIN SELECT (PPS) MODULE
The Peripheral Pin Select (PPS) module connects peripheral inputs and outputs to the device I/O
pins. Only digital signals are included in the selections. All analog
inputs and outputs remain fixed to their assigned pins. Input and
output selections are independent as shown in the simplified block
diagram Figure 12-1.
12.2 PPS Outputs
Each I/O pin has a PPS register with which the pin output source is
selected. With few exceptions, the port TRIS control associated with
that pin retains control over the pin output driver. Peripherals that
control the pin output driver as part of the peripheral operation will
override the TRIS control as needed. These peripherals include:
12.3 Bidirectional Pins
PPS selections for peripherals with bidirectional signals on a single
pin must be made so that the PPS input and PPS output select the same
pin. Peripherals that have bidirectional signals include:
You should read the relevant parts of the data sheet, and set up all I/O configuration registers needed for your configuration. In this case, setting up ANSELB to enable the digital inputs, and setting up the PPS registers to route the input & output functions of the I2C module to the desired pins is missing. Also, the PPS registers are protected from undesired changes, so there is a locking mechanism you have to use before you could access the registers.
After making the changes above, the code should look something like this. Note that since the I2C messages aren't being properly acknowledged yet, the device may not be "visible" to the master, but you should at least see the light blink.
#include <xc.h> /* XC8 General Include File */
#include <pic16lf1709.h> /* Definitions of I/O pins */
#pragma config WDTE = OFF
// I2C address is 7 bits: 1111110
#define I2C_ADDRESS 0x6E
typedef unsigned char byte;
void main(void) {
/* configure ports */
TRISBbits.TRISB4 = 1; // set SDA to input
TRISBbits.TRISB6 = 1; // set SCL to input
ANSELBbits.ANSB4 = 0; // make sure SDA is set to digital
TRISC = 0x00; // set LEDs to output
PORTC = 0xFF; // initialize LEDs to OFF
/* configure peripheral pin select */
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCK = 0x00; // PPS is now unlocked
SSPDATPPS = 0x0C; // RB4 input is SDA (pg 140)
SSPCLKPPS = 0x0E; // RB6 input is SCL (pg 140)
RB4PPS = 0x11; // RB4 output is SDA (pg 141)
RB6PPS = 0x10; // RB6 output is SCL (pg 141)
PPSLOCK = 0x55;
PPSLOCK = 0xAA;
PPSLOCK = 0x01; // PPS is now locked
/* configure MSSP module */
SSPCON1bits.SSPEN = 1; // enable SSP module
SSPCON1bits.SSPM = 0x6; // SSP is in I2C slave mode, 7-bit addressing
SSP1ADD = I2C_ADDRESS<<1; // set the device address (left-aligned)
SSPCON1bits.CKP = 1; // release clock
while(1) {
byte ssp_buf;
if(SSPSTATbits.BF) { // if the I2C buffer is not empty
PORTC = 0x00; // turn on LEDs for a moment
for(int i=0; i<100; i++) _delay(250);
PORTC = 0xFF; // turn them back off
ssp_buf = SSPBUF; // read the buffer
// BF flag is cleared by hardware
}
SSPCON1bits.CKP = 1; // finally, release clock
}
}
Best Answer
I shall answer your second part first.
Certainly not, no. Simply because native Windows code need Windows to run, and needs to be compiled for the host processor - and neither of those can be done on a little Atmel.
The first part of your question:
Almost certainly, yes. Look on the Atmel site, you will find some. I personally am not up on Atmel, but all the other manufacturers I can think of provide either full example code, or libraries to incorporate in your own code (such as Microchip's Harmony library), so Atmel certainly will too.