 |
 |
| View previous topic :: View next topic |
| Author |
Message |
bkamen
Joined: 07 Jan 2004 Posts: 1619 Location: Central Illinois, USA
|
|
Posted: Sat Feb 02, 2013 3:10 pm |
|
|
| Ttelmah wrote: | I'd separate things.
Try:
| Code: |
RcvVal=spi_read();
spi_write(IntrTriggered++);
|
If you read the manual entry for spi_read, it says that if you pass it a variable, it will wait for this to be clocked out, and then read the returned value - of course this will be the byte you have just sent.
You want to do things the other way round, read what has been clocked to you, and then load the output buffer. spi_write, if called in an ISR, only loads the output buffer.
|
I was thinking about that too...
normally, in ISR's, I'm a little more "direct to register" with my operations because I know a lot of the CCS functions have checks in them which can foul up an ISR.
I would concur with your suggestion to use the spi_write...
or, what I would do is define a byte/word to point to the spi buffer something like:
| Code: |
#word spibuf = getenv("sfr:SPI1BUF")
|
And in the ISR:
| Code: |
rxval = spibuf;
spibuf = txval;
|
It's really important when using CCS routines to check the assembly output for the extra stuff it might be doing.
Not that CCS routines are bad, but they hide details of their operation which are sometimes important.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20161
|
|
Posted: Sat Feb 02, 2013 3:44 pm |
|
|
Very true.....
Best Wishes |
|
 |
john.ma
Joined: 19 Nov 2012 Posts: 23
|
|
Posted: Sat Feb 02, 2013 6:12 pm |
|
|
Thanks guys, semi good news... it works about 50-60% of the time now as shown below in the output log. I toggled the power to the circuit a few times to gather a few outputs.
Whats interesting is in the instances when is incorrect, the values are padded with a 8x value.
Anyone seen anything like this before? The sample data is hard coded, thus its strange that it sometimes doesnt work on a ~50/50 basis.
Thanks a lot everyone, so nice having a forum full of veterans
Master chip sample data:
Start from one and count up...
| Code: | | int8 SPIsampleData[bufferSize]={1,2,3,4,5,6,7,8,9,10,11,0xFF,13}; |
Slave output (received data):
| Quote: |
Successful, waiting for input...
SPI activity: 1, buf: 0, val: 01
SPI activity: 2, buf: 1, val: 02
SPI activity: 3, buf: 2, val: 03
SPI activity: 4, buf: 3, val: 04
SPI activity: 5, buf: 4, val: 05
SPI activity: 6, buf: 5, val: 06
SPI activity: 7, buf: 6, val: 07
SPI activity: 8, buf: 7, val: 08
SPI activity: 9, buf: 8, val: 09
SPI activity: 10, buf: 9, val: 0A
SPI activity: 11, buf: 10, val: 0B
SPI activity: 12, buf: 11, val: FF
SPI activity: 13, buf: 12, val: 0D
SPI Values: (0,0x01) (1,0x02) (2,0x03) (3,0x04) (4,0x05) (5,0x06) (6,0x07) (7,0x
08) (8,0x09) (9,0x0A) (10,0x0B) (11,0xFF) (12,0x0D)
SPI2STAT -> 8000
SPI2CON1 -> 00c0
SPI2CON2 -> 0000
Successful, waiting for input...
SPI activity: 1, buf: 0, val: 00
SPI activity: 2, buf: 1, val: 81
SPI activity: 3, buf: 2, val: 01
SPI activity: 4, buf: 3, val: 82
SPI activity: 5, buf: 4, val: 02
SPI activity: 6, buf: 5, val: 83
SPI activity: 7, buf: 6, val: 03
SPI activity: 8, buf: 7, val: 84
SPI activity: 9, buf: 8, val: 04
SPI activity: 10, buf: 9, val: 85
SPI activity: 11, buf: 10, val: 05
SPI activity: 12, buf: 11, val: FF
SPI activity: 13, buf: 12, val: 86
SPI Values: (0,0x00) (1,0x81) (2,0x01) (3,0x82) (4,0x02) (5,0x83) (6,0x03) (7,0x
84) (8,0x04) (9,0x85) (10,0x05) (11,0xFF) (12,0x86)
SPI2STAT -> 8000
SPI2CON1 -> 00c0
SPI2CON2 -> 0000
Successful, waiting for input...
SPI activity: 1, buf: 0, val: 01
SPI activity: 2, buf: 1, val: 02
SPI activity: 3, buf: 2, val: 03
SPI activity: 4, buf: 3, val: 04
SPI activity: 5, buf: 4, val: 05
SPI activity: 6, buf: 5, val: 06
SPI activity: 7, buf: 6, val: 07
SPI activity: 8, buf: 7, val: 08
SPI activity: 9, buf: 8, val: 09
SPI activity: 10, buf: 9, val: 0A
SPI activity: 11, buf: 10, val: 0B
SPI activity: 12, buf: 11, val: FF
SPI activity: 13, buf: 12, val: 0D
SPI Values: (0,0x01) (1,0x02) (2,0x03) (3,0x04) (4,0x05) (5,0x06) (6,0x07) (7,0x
08) (8,0x09) (9,0x0A) (10,0x0B) (11,0xFF) (12,0x0D)
SPI2STAT -> 8000
SPI2CON1 -> 00c0
SPI2CON2 -> 0000
Successful, waiting for input...
SPI activity: 1, buf: 0, val: 01
SPI activity: 2, buf: 1, val: 02
SPI activity: 3, buf: 2, val: 03
SPI activity: 4, buf: 3, val: 04
SPI activity: 5, buf: 4, val: 05
SPI activity: 6, buf: 5, val: 06
SPI activity: 7, buf: 6, val: 07
SPI activity: 8, buf: 7, val: 08
SPI activity: 9, buf: 8, val: 09
SPI activity: 10, buf: 9, val: 0A
SPI activity: 11, buf: 10, val: 0B
SPI activity: 12, buf: 11, val: FF
SPI activity: 13, buf: 12, val: 0D
SPI Values: (0,0x01) (1,0x02) (2,0x03) (3,0x04) (4,0x05) (5,0x06) (6,0x07) (7,0x
08) (8,0x09) (9,0x0A) (10,0x0B) (11,0xFF) (12,0x0D)
SPI2STAT -> 8000
SPI2CON1 -> 00c0
SPI2CON2 -> 0000
Successful, waiting for input...
SPI activity: 1, buf: 0, val: 00
SPI activity: 2, buf: 1, val: 81
SPI activity: 3, buf: 2, val: 01
SPI activity: 4, buf: 3, val: 82
SPI activity: 5, buf: 4, val: 02
SPI activity: 6, buf: 5, val: 83
SPI activity: 7, buf: 6, val: 03
SPI activity: 8, buf: 7, val: 84
SPI activity: 9, buf: 8, val: 04
SPI activity: 10, buf: 9, val: 85
SPI activity: 11, buf: 10, val: 05
SPI activity: 12, buf: 11, val: FF
SPI Values: (0,0x00) (1,0x81) (2,0x01) (3,0x82) (4,0x02) (5,0x83) (6,0x03) (7,0x
84) (8,0x04) (9,0x85) (10,0x05) (11,0xFF) (12,0x86)
SPI activity: 13, buf: 12, val: 86
SPI2STAT -> 8000
SPI2CON1 -> 00c0
SPI2CON2 -> 0000
Successful, waiting for input...
SPI activity: 1, buf: 0, val: 01
SPI activity: 2, buf: 1, val: 02
SPI activity: 3, buf: 2, val: 03
SPI activity: 4, buf: 3, val: 04
SPI activity: 5, buf: 4, val: 05
SPI activity: 6, buf: 5, val: 06
SPI activity: 7, buf: 6, val: 07
SPI activity: 8, buf: 7, val: 08
SPI activity: 9, buf: 8, val: 09
SPI activity: 10, buf: 9, val: 0A
SPI activity: 11, buf: 10, val: 0B
SPI activity: 12, buf: 11, val: FF
SPI Values: (0,0x01) (1,0x02) (2,0x03) (3,0x04) (4,0x05) (5,0x06) (6,0x07) (7,0x
08) (8,0x09) (9,0x0A) (10,0x0B) (11,0xFF) (12,0x0D)
SPI activity: 13, buf: 12, val: 0D
|
|
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20161
|
|
Posted: Sun Feb 03, 2013 2:02 am |
|
|
I'd say the rules are the same as for when you want to make a chip sleep.
_All_ pins must be one of:
1) Driven by another chip - then set as input.
2) Driven as outputs.
3) Driven by something else (resistor etc..) - again can be set as inputs.
There is a very significant difference between a pin set as an input, with nothing connected, and a pin set as an input, that is connected to other circuitry, which itself (hopefully) supplies capacitance, resistance, and probably diode clamping.
It looks as if the SPI clock input on the later PIC's is possibly rather over sensitive, and is picking up spikes on the internal supply of the chip, when this acts to trap spikes coming in from other floating pins.
Interesting annoyance.
Best Wishes |
|
 |
john.ma
Joined: 19 Nov 2012 Posts: 23
|
|
Posted: Sun Feb 03, 2013 4:42 am |
|
|
Just reread my previous post and realised my English was appalling, sorry about that...
1. Thanks a million guys... this would have taken me another week to figure out by myself. Really, thanks.
2. I thought if its electrostatic noise I could perhaps alter the idle state of the clock and see what effect that has. Interestingly it was consistently the wrong input, but always the same wrong input. So I changed it back.
3. Set all other pins as outputs, which made it correct 90% of the time.
4. Installed pull-down resistors and its consistently correct. However, if I comment out the "set all other pins to outputs" nothing works anymore, e.g. the interrupt doesn't even trigger.
And that's how my engineering degree turned into a black magic course...
Didn't realise just how hyper-sensitive the components were to ESD.
Probably compound influences of the moons relative position and the temperature of my coffee have some effect as well.
Thanks a mil everyone, you guys are legends.
Regards,
John |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20161
|
|
Posted: Sun Feb 03, 2013 9:23 am |
|
|
| and, of course whether you have killed the chicken correctly.... |
|
 |
|
|
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
|