krugger
Joined: 12 Jul 2011 Posts: 18 Location: El Salvador
|
spi_xfer for more than 8 bits |
Posted: Fri Nov 25, 2011 11:59 am |
|
|
Hi everybody,
I'm working in a project in which I need to communicate a PIC 16F1827 with an VDIP2 module by FTDI.
This module uses a -let's say funny- SPI that needs 13 bits to be transmitted per each instruction (read or write, chronogram for a write instruction below).
I'm trying to develop the communication using SW SPI (#USE SPI and spi_xfer), but before using it in my project I've been experimenting with them in a dummy program.
I could send an arbitrary number of bits below 8 properly, but when I try to send more than 8 bits, only the last 8 are sent correctly and the others are simply not sent. This is the simple code of my program:
Code: |
#include <SPI_VDIPsimple.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdlibm.h>
#include <string.h>
#USE SPI (MASTER, DO=PIN_B2, DI=PIN_B1, CLK=PIN_B4, ENABLE=PIN_B7, BAUD = 1000, MODE=2, BITS=13, ENABLE_ACTIVE=1, STREAM=VDIP, MSB_FIRST)
void main()
{
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
int cuatro=0b1010;
int ocho = 0xFF;
int doce = 0xFFF;
int trece = 0b11001000101;
spi_xfer(0xAA);
spi_xfer(VDIP,cuatro,4);
spi_xfer(VDIP,ocho,8);
spi_xfer(VDIP,doce,12);
spi_xfer(VDIP,trece,13);
}
|
and this is what I get when I try it in Proteus (I've checked it also with an osciloscope just to see if it was some kind of bug in Proteus and I obtain exactly the same)
(blue trace for SDO, red trace for SCK and green trace for CS)
What am I doing wrong? I'm using CCS 4.114.
Thank in advance for your time and help.
Pablo |
|