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.

Strange SPI Problem with PIC18F2553

Status
Not open for further replies.

zappedOne

Newbie level 1
Joined
Aug 26, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
New Zealand
Activity points
1,288
pic spi probleme

Hi

I have set up a master and a slave PIC using the SPI Library.
I am using the two PWM modules on each PIC.

My problem is when I write a value to the slave PWM modules over SPI it always gets doubled??

The time settings and crystals for both PICs are all the same values.

I can fix the problem with the bottom two lines of code:

Code:
  CCPR1L = ReadSPI();
		CCPR2L = ReadSPI();
		
		CCPR1L = (CCPR1L/2);
		CCPR2L = (CCPR2L/2);


But I would really like to discover what I am actually doing wrong...


This is most of the relevant code for the Master:

Code:
void parse_PWM_packet(void)
{
	
	unsigned char value1;
	unsigned char value2;
	unsigned char value3;
	unsigned char value4;

	value1 = extract_number (kUINT);
	value2 = extract_number (kUINT);
	value3 = extract_number (kUINT);
	value4 = extract_number (kUINT);

	if (error_byte)
	{
		return;
	}


	CCPR1L = value1; 
	CCPR2L = value2;
	
	OpenSPI(SPI_FOSC_4,MODE_01,SMPMID);
	

	WriteSPI(value3);
        while (0 != (WriteSPI(value3)))
	{    
 	WriteSPI(value3);
	printf ((far rom char *)"PWM3 collision");
	}
	

	WriteSPI(value4);
        while (0 != (WriteSPI(value4)))
	{    
 	WriteSPI(value4);
	printf ((far rom char *)"PWM4 collision");
	}   

	CloseSPI();

	print_ack ();
}





And this is most of the relevant code for the Slave:
Code:
	OpenSPI(SLV_SSOFF,MODE_01,SMPMID);
		
		CCPR1L = ReadSPI();
		CCPR2L = ReadSPI();

	CloseSPI();

Thanks for any suggestions
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top