View previous topic :: View next topic |
Author |
Message |
Jeetdesai
Joined: 05 Jul 2018 Posts: 18
|
How to transmit characters/special characters over SPI? |
Posted: Tue Jul 10, 2018 8:44 am |
|
|
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
|
|
Posted: Tue Jul 10, 2018 9:34 am |
|
|
Quote: | spi_write("A"); //Char data | This is not the correct way to do it.
The correct way is to use single quotes:
|
|
|
Jeetdesai
Joined: 05 Jul 2018 Posts: 18
|
|
Posted: Tue Jul 10, 2018 9:46 am |
|
|
Thanks You so much !!! |
|
|
|