Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[MOVED] SPI communication problem

Status
Not open for further replies.

Arrowspace

Banned
Joined
Jan 23, 2015
Messages
186
Helped
3
Reputation
6
Reaction score
3
Trophy points
18
Activity points
0
I am trying to communicate with a device using SPI communication and trying to display slave data on my LCD connected with master by LCD always showing AAAA or 0000 charter

I have attached pic of dataout my slave device

dataout1.png

dataout2.png
 

What exactly LCD has to show? Which controller or processor is you master and which is your slave device. Is your interface between the devices (Master, Slave and LCD) are correct?
 

PIC18F4550 and ADC my connection MISO - MOSI
 

yes 6VDC at ADC input

- - - Updated - - -

actually you can see that image last bit have a shape like discharging through capacitor . I do't understand that
 

What is your ADC operating voltage level...
 

Provide the ADC part number and post the circuit... will try to analyse
 

Is the USB module of the pic18f4550 is running? I think that the interrupt used by the USB every 1ms stops the ISP module on its track and the ISP stops sending/receiving data. I haven't found a solution for that yet.
 

Have you also face that problem?

How can I turn off USB

Code:
#pragma config PLLDIV = 1          
#pragma config CPUDIV = OSC4_PLL6                            
#pragma config FOSC = INTOSC_HS    
#pragma config USBDIV = 1          
#pragma config IESO = OFF        
#pragma config PWRT = OFF        
#pragma config BOR = OFF        
#pragma config VREGEN = OFF  
#pragma config WDT = OFF     
#pragma config WDTPS = 32768     
#pragma config CCP2MX = ON       
#pragma config PBADEN = OFF      
#pragma config LPT1OSC = OFF         
#pragma config MCLRE = ON            
#pragma config STVREN = ON       
#pragma config LVP = OFF     
#pragma config ICPRT = OFF       
#pragma config XINST = OFF       
#pragma config DEBUG = OFF
#pragma config WRTD = OFF
 
Last edited by a moderator:

Have you also face that problem?

How can I turn off USB

To disable USB add to your code: USBEN=0;
If You are using the pic for ISP and ADC only and there is no USB code in your program then what that I said in my previous post doesn't apply, ignore it.
 

I do't have any USB code in my program, is this a software or hardware problem ?
 

You haven't really given us much information, other than two oscilloscope traces that tell us exactly nothing. Where are those signals coming from? Where are they going to? Does the data look like you expected? Do you have a debugger (PICKIT, ICD,etc)? Have you used it? Have you simulated and verified your software?
 

I don't know if my problem is hardware of software, it is more likely software.
The USB works ok when the code includes USB only, the ISP works ok when the code is for ISP only, when the code includes both USB and ISP the USB works ok but the ISP doesn't.
 

See my code

Code:
void spi_master_init ( void )
{

TRISC &= 0b00001111;    // clear 7th bit keeping all other bits unchanged (SDO output)                         
TRISB &= 0b00001101; // clear 1th bit keeping all other bits unchanged (SCK output)
TRISA |= 0x20; // clearing 5th bit, SS as output
 
ADCON0 = 0x3C; // Disabling the ADC module which is multiplexed with SPI pins
ADCON1 = 0x0F; // Disabling the ADC module which is multiplexed with SPI pins
CMCON = 0x00; // Disabling the COMPARATOR module which is multiplexed with SPI pins
SPPCON = 0x00; // Disabling the SERIAL PERIPHERAL CONTROL module which is multiplexedwith SPI pins 
 
TRISD &= 0xFE; // Clearing 0th pin of PORTD as output ( SS for the slave ) 
PORTD |= 0x01; // Setting 0th pin of PORTD ( Slave not selected )

SSPSTAT = 0b000000000; // SMP=0(slave mode),CKE=0(transmission on Idle to active clock state),all other bits 0       
SSPCON1 = 0x22; // SSPEN = 1 (enable serial port), SSPM[3-0] = 0b0010 (master mode,clcok=FOSC/64), all other bits are zero                                        
 
}    
 
/*============================================
Function : to send and receive SPI data

=============================================*/
unsigned char spi_data ( unsigned char tx_data )
{
unsigned int data_read3;
 
cs=0; // Enabling the slave

SSPCON1bits.WCOL=0;     //Clear the collision
 SSPSTATbits.BF=0;       //and Buffer Full control bits.
 
SSPBUF = tx_data;        // put the data in the SSPBUF register which going to be send


while ( !SSPSTATbits.BF );        // wait until the all bits received
 
SSPSTATbits.BF=0;

data_read1 = SSPBUF; // read the received data from the buffer
data_read2 = SSPBUF; // read the received data from the buffer
data_read3 =  data_read1 || (data_read2<<8); // read the received data from the buffer

cs=1; // Disabling the salve
 
 
return data_read3;
}
 

This is only part of the code, of course.
I suspect you will have an error returning unsigned int with this function: unsigned char spi_data ( unsigned char tx_data )
 
But my data is 16-bit , can't store in unsigned char
 

I think it's a software problem which affects hardware.

What if the measured output is put as hi-z once the transmission has been completed? Parasitic capacitance would store that "1" (3v3, 5v, etc) voltage theorically forever since there's no bias current. There's a real resistance (because of the semiconductors and the scope probe) which could be discharging that parasitic capacitor (that's why the exponential discharge).

You could try (you don't lose anything) connecting a pull down resistor in the transmission line (about 10K or different values). If that fall time decreases then the problem is a hi-z output. If you could measure both lines simultaneously with different pull-down resistors it would be even better.

Hope being useful.
 

But my data is 16-bit , can't store in unsigned char

Since you return int your function has to be; unsigned int spi_data ( unsigned char tx_data )
You are in master mode so for receiving 2 bytes you have to transmit 2 bytes. With your code you are reading the same byte twice.
Clearing BF and WCOL isn't important, try without it.

Code:
unsigned int spi_data ( unsigned char tx_data )
{
unsigned int data_read3;

cs=0; // Enabling the slave

//SSPCON1bits.WCOL=0;     //Clear the collision   
//SSPSTATbits.BF=0;       //and Buffer Full control bits.

SSPBUF = tx_data;        // put the data in the SSPBUF register which going to be send
while ( !SSPSTATbits.BF );        // wait until the all bits received

//SSPSTATbits.BF=0;

data_read1 = SSPBUF; // read the received data from the buffer
 
SSPBUF = tx_data;        // put the data in the SSPBUF register which going to be send
while ( !SSPSTATbits.BF );        // wait until the all bits received

data_read2 = SSPBUF; // read the received data from the buffer
data_read3 =  data_read1 || (data_read2<<8); // read the received data from the buffer

cs=1; // Disabling the salve
 
return data_read3;
}
 

Thanks Vbase I start receiving data on my LCD, as you written, tomorrow I w'll try to receive 2 byte of data.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top