chipKIT® Development Platform

Inspired by Arduino™

DSPI Library and Serial Input.

Created Fri, 24 Feb 2012 22:57:30 +0000 by MarkHoskins


MarkHoskins

Fri, 24 Feb 2012 22:57:30 +0000

I'm using DSPI to command an SD card and I found that if you simply include the DSPI header, any received Serial communication crashes the Chipkit.

This simple sketch crashes when you send it a serial character:

#include <WProgram.h>
#include <DSPI.h>

void setup()
{
  Serial.begin( 9600 );
  while( true )
  {
    Serial.println( Serial.read() );
  }
}

void loop()
{
}

This code does not:

#include <WProgram.h>

void setup()
{
  Serial.begin( 9600 );
  while( true )
  {
    Serial.println( Serial.read() );
  }
}

void loop()
{
}

Don't even know where to start on this one.


Ryan K

Sat, 25 Feb 2012 01:04:33 +0000

Hello,

Can you give me more details on your configuration? I just tried your first set of code on a chipkit Uno32 and it seems to work fine. Let me know what board, peripherals, and version of MPIDE you are using.

Best Regards, Ryan K


MarkHoskins

Mon, 27 Feb 2012 17:15:44 +0000

I'm using MPIDE 0023-windows-20111221 with a chipkit Max32. I have a chipkit network shield attached, I have a plain chipkit max32 to try it against, I'll try that.


MarkHoskins

Mon, 27 Feb 2012 17:23:58 +0000

Doesn't work for Chipkit Max32 with no peripherals either.


compuwizard123

Thu, 15 Mar 2012 18:01:06 +0000

I can confirm this happens as well.


MarkHoskins

Thu, 15 Mar 2012 18:45:16 +0000

Thanks for trying it out, thought I was going crazy.


compuwizard123

Tue, 20 Mar 2012 19:36:35 +0000

I think this has to do with the ISR being the same for UART and SPI. This is defined as shown below in "mpide\hardware\pic32\cores\pic32\System_Defs.h" around line 287.

To get around this I changed NUM_DSPI_PORTS to 2 in "mpide\hardware\pic32\variants\Max32\Board_Defs.h" around line 71. This avoids confusing the ISR for SPI3 with UART1.

I hope to look into this further, but won't be able to for a few weeks probably.

#if defined(__PIC32MX5XX__) || defined(__PIC32MX6XX__) || defined(__PIC32MX7XX__)
#define	_SPI2_IPL_ISR	_UART3_IPL_ISR	//shared with UART3
#define	_SPI2_IPL_IPC	_UART3_IPL_IPC
#define	_SPI2_SPL_IPC	_UART3_SPL_IPC

#define	_SPI3_IPL_ISR	_UART1_IPL_ISR	//shared with UART1
#define	_SPI3_IPL_IPC	_UART1_IPL_IPC		
#define	_SPI3_SPL_IPC	_UART1_SPL_IPC

#define	_SPI4_IPL_ISR	_UART2_IPL_ISR	//shared with UART2
#define	_SPI4_IPL_IPC	_UART2_IPL_IPC
#define	_SPI4_SPL_IPC	_UART2_SPL_IPC
#endif

mhanuel

Mon, 24 Sep 2012 03:03:40 +0000

I have the same problem. If I include DSPI.h in my sketch, the Serial2 stop working. I am using MAX32 so changing the DSPI ports numbers give a lot of compile error.

Actually i need to use DSPI2 and all serial ports.

I really don't understand the IPL definitions and how that affect the serial port execution. (#define _SPI2_IPL_ISR _UART3_IPL_ISR )

I would appreciate any comment,

Best


mhanuel

Thu, 27 Sep 2012 02:48:45 +0000

I have noted that if I remove te ISR of DSPI3 from DSPI.cpp my program works as expected. That is, the last lines in DSPI.cpp

#if defined(_DSPI3_VECTOR)

void __ISR(_DSPI3_VECTOR, _DSPI3_IPL_ISR) IntDspi3Handler(void) {
	if (pdspi3 != 0) {
		pdspi3->doDspiInterrupt();
	}
}
#endif

If you review the file Board_Defs.h (line 374) and then System_Defs.h (line 298), you will found out that ISR of DSPI3 is assigned to the same ISR of UART2 (correct me if I am wrong).

Fortunately my application uses DSPI0. I am not sure whether or not Serial1 is affected by DSPI.

Any comments about how this can be workaround would be appreciated.

Best,