CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

spi_xfer for more than 8 bits

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
krugger



Joined: 12 Jul 2011
Posts: 18
Location: El Salvador

View user's profile Send private message

spi_xfer for more than 8 bits
PostPosted: Fri Nov 25, 2011 11:59 am     Reply with quote

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
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 25, 2011 2:06 pm     Reply with quote

Quote:

int trece = 0b11001000101;

This can't work. An 'int' in CCS is different than ANSI C. It's an 8-bit
unsigned integer in CCS. Your number above is 11 bits.

Download the CCS manual.
http://www.ccsinfo.com/downloads/ccs_c_manual.pdf
Read this section. It explains CCS data types:
Quote:

Basic and Special types
krugger



Joined: 12 Jul 2011
Posts: 18
Location: El Salvador

View user's profile Send private message

PostPosted: Fri Nov 25, 2011 3:27 pm     Reply with quote

Thanks PCM.

Changed the variables doce and trece for an int16 and works perfectly.

Sorry for the silly question.

Embarassed

Pablo
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group