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 CCS Technical Support

How to transmit characters/special characters over SPI?

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



Joined: 05 Jul 2018
Posts: 18

View user's profile Send private message

How to transmit characters/special characters over SPI?
PostPosted: Tue Jul 10, 2018 8:44 am     Reply with quote

I can successfully transmit decimal, hex and binary data over SPI. I check my signals by connecting the oscilloscope probes at the data out, clock and enable pins, and observe the waveforms.

But i'm getting the wrong data when I send characters(A, B ... Z)) or special characters(!, @ ... +). The waveform on the output is the same (01100111) for all alphabetic characters and special characters.

The following is my code:

Code:
#include <18F87K22.h> 
#FUSES INTRC_IO                  //Internal RC Osc, no CLKOUT
//#FUSES NOPUT                     //No Power Up Timer
#FUSES NOPROTECT                 //No code protected from reads
#FUSES MCLR                      //Master Clear pin enabled
#FUSES NOCPD                     //No EE protection
#FUSES NOBROWNOUT                //No brownout reset
//#FUSES BROWNOUT                  // Hold in reset during brownout - else can corrupt EEPROM, act strange, etc
#FUSES NOIESO                    //Internal External Switch Over mode disabled
#FUSES NOFCMEN                   //Fail-safe clock monitor disabled   
#use delay(clock = 1000000)   
#define CS Pin_H0
//#BYTE ODCON1=
//#BIT  ODCON1BIT7 = ODCON1.7

/*#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H) */

//========================================
void main()
{

setup_spi(SPI_MASTER | SPI_H_TO_L| SPI_CLK_DIV_64);

while(1)
  {
   output_low(CS);

   //spi_write(0x55); //hex data
   //spi_write(75); // decimal
   //spi_write(0b11110000); // binary
   spi_write("A"); //Char data
 
   output_high(CS);
   delay_us(1000);
   
  }

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jul 10, 2018 9:34 am     Reply with quote

Quote:
spi_write("A"); //Char data
This is not the correct way to do it.

The correct way is to use single quotes:
Code:
spi_write('A');
Jeetdesai



Joined: 05 Jul 2018
Posts: 18

View user's profile Send private message

PostPosted: Tue Jul 10, 2018 9:46 am     Reply with quote

Thanks You so much !!!
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