 |
 |
| View previous topic :: View next topic |
| Author |
Message |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Wed Oct 17, 2007 8:15 pm |
|
|
Right now all of the SPI transactions are handled within an interrupt. So I don't think that's an issue. It could be if I had high priority interrupts enabled, no? But, I just double checked and made sure that wasn't left over from some cutting and pasting.
The MAX3100 will drop any incomplete transaction. (i.e. CS goes high before 16th bit.)
Everything, right now, is pointing at bad SPI. I'll write one value and read a slightly different one back. That's what I'm working on now.
Thanks for the ideas. Anything is much appreciated.
John
EDIT:
Newguy,
You may be on to something. There is a delay between the individual bytes in the current code. The delay becomes less noticeable as divide the spi clock. At clk_div_64 it almost looks consistent across the two bytes.
I should know whether that's the problem as soon as I can get the bit-bang routine working.
EDIT #2:
Newguy,
The bit-banged code works. I think there may be some problem with the delay in the SPI transaction between bytes. The less you divide the clock, the more exaggerated it becomes in relation to the bit timing.
When I have a chance, I'll throw an artificial delay into my bit-banged code and see if it causes similar problems. |
|
 |
Ttelmah Guest
|
|
Posted: Thu Oct 18, 2007 2:24 am |
|
|
There is one thing that hasn't been mentioned. I queried silicon revisions for the Maxim chip, what about your PIC?. This is the obvious difference between my systems and yours, since I am sure we are almost certainly not using the same PIC...
I have run my code, with the 18F252, and with the 18F2550.
The number of SPI 'errors' on PICs is high, and often others seem to exist that haven't been found yet.
On the 18F6627, there is an interesting one if using timer2, where it'll generate a shorter clock pulse than it should. Though this should not apply with the master oscillator source, it'd be worth looking at the SPI bit timings (given that you are already to my mind 'borderline' on the spec for the MAX3100, which says minimum high/low times of 100nSec, and cycle time of 238nSec). Also note the 'write collision' one, where the transmit buffer is reloaded immediately after a transmission. Though they say it has not been seen at the faster clock rates, the wording suggests they may expect it to happen here as well.
The one though that is the 'killer', and is probably causing the problem, is number 29. It looks as though the code will need to be modified to work with the 6627, as follows:
| Code: |
int8 SSPREG
#DEFINE WAIT_FOR_SSP() do {\
SSPREG=SSPSTAT;\
} while((SSPSTAT & 1)==0)
|
Best Wishes |
|
 |
Ttelmah Guest
|
|
Posted: Thu Oct 18, 2007 2:26 am |
|
|
Aargh!. Try:
| Code: |
int8 SSPREG
#DEFINE WAIT_FOR_SSP() do {\
SSPREG=SSPSTAT;\
} while((SSPREG & 1)==0)
|
Best Wishes |
|
 |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Thu Oct 18, 2007 7:31 am |
|
|
Will try that later today. Thanks for the interpretation of the errata and the fix.
So far, there has been two 'phenomena' that I can't explain.
1. Why everything works (even at the fastest SPI) when I comment out the enable and disable GLOBAL interrupt changes in the maxputc and instead do it before and after the 'batch' maxputc loop.
2. When I see the failure on the scope (send 16 characters, and it quits after six) ALWAYS the IRQ line returns HIGH early right as it quits. Almost as though it drops low and returns high immediately thereafter. |
|
 |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Thu Oct 18, 2007 3:53 pm |
|
|
No luck with that fix.
Here's a question. If I do this:
(this is the test that works)
| Code: |
disable_interrupts(GLOBAL);
for(i=0;i<16;i++)
{
maxputc_rgl(i + 0x30);
}
enable_interrupts(GLOBAL); |
It Fills the software buffer before starting to TX. Why would that work but not the starting and stopping with the normal code? |
|
 |
newguy
Joined: 24 Jun 2004 Posts: 1946
|
|
Posted: Thu Oct 18, 2007 4:46 pm |
|
|
| That's what I was getting at with the timing-related things I was pondering. If you disable interrupts before attempting any transactions at all, you know that the timings between bytes and indeed between entire transfers will be consistent because the processor isn't getting distracted by interrupts. Disabling interrupts just before you start an individual SPI transaction doesn't guarantee consistent timing between adjacent transactions - perhaps these added delays are playing a role? Obviously they are, but the bigger question is why? |
|
 |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Thu Oct 18, 2007 5:43 pm |
|
|
Newguy,
But the delay that is between each byte transaction can't be interrupt related. The tx/rx happens within the ISR. The delay is a function of waiting for the first byte to finish prior to starting the second.
| Code: | // routine to send and receive a 16bit value from the Maxim chip inside INT
// keep separate, to avoid automatic interrupt controls.
int16 iSSPtransfer16(int16 val, int8 radio)
{
int8 msb;
RGL_CS_BIT = 0;
delay_cycles(5);
WRITE_SSP(make8(val,1)); // send high byte
WAIT_FOR_SSP(); // wait until the SSP return character is ready
msb=READ_SSP(); // read the SSP character and save it
WRITE_SSP(make8(val,0)); // now send the low byte
WAIT_FOR_SSP(); // wait until the SSP return character is ready
delay_cycles(5);
RGL_CS_BIT = 1;
return(make16(msb,READ_SSP())); // read the SSP character and combine it with msb and return
} |
I'm going to do some more experimenting now with the scope and see if the artificial delay in the bit-bang code causes a failure. (I haven't been very productive today w/ shoulder surgery this morning and the V i c o d i n this afternoon.) |
|
 |
newguy
Joined: 24 Jun 2004 Posts: 1946
|
|
Posted: Thu Oct 18, 2007 6:00 pm |
|
|
| What I was getting at is that if you have other interrupts (timers, external interrupts, etc) enabled - if they happen to fire during this entire procedure they will alter the timing. |
|
 |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Thu Oct 18, 2007 6:27 pm |
|
|
Well, I guess I should Have checked this earlier. MAX3100 minimum clock timing is 100nS (from clock going from high to low or vice versa). I don't get above that (checked on the scope) until spi_clk_div_16. At that speed it's right about 200nS. However there is a 1500nS delay between the two bytes. (BTW it still fails at clk_16)
FWIW.
What I can't grasp is, why it would fail with a 'string' of characters, because the code handles each individually. It's got to be as Ttelmah says a problem within the register updates on the MAX3100. That's what I'm seeing at the point of failure when the IRQ is released prematurely. |
|
 |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Fri Oct 19, 2007 12:28 am |
|
|
Some observations:
The 100nS clock timing spec is EXTREMELY conservative. I have everything working with a 20nS clock that doesn't look that pretty (kindof rounded edges.)
The crux of my problem has been isolated to the writing of the configuration during every maxputc or as Ttelmah has observed, the updating of the TX interrupt.
| Code: | void maxputc_lcl(int8 chr)
{
int16 tval;
disable_interrupts(GLOBAL); // put the character in the tx buffer
tobuff(MAXOPbuff_lcl,MAXOPin_lcl,MAXOPout_lcl,SOBUFF,chr);
Mconfig_lcl = Mconfig_lcl | 0xC800; // set tx buffer interrupt bit (turn on interrupt)
tval=SSPtransfer16(Mconfig_lcl, LCL); // enable tx buffer interrupt bit (turn on interrupt)
EXT3IF = 1; // force an interrupt to start transmission
enable_interrupts(GLOBAL);
} |
I have (I think) a valid work around that doesn't rely on the TX interrupt. Ttelmah, I would like your feelings/input on this.)
I remove the two lines in maxputc that update the TX INTERRUPT on the MAX3100. I then modify the EXT_INT code:
(note: these two function relate to two different radios, so their variables won't quite agree.)
| Code: | #INT_EXT2 NOCLEAR //Interrupt from local radio Maxim chip
void maxim_rgl(void)
{
unsigned int16 Rxdata;
do
{
Rxdata = iSSPtransfer16(0L, RGL); // force a read
if (Rxdata & 0x8000L) // if a character is returned from the read
{ // put it in the MAXIPbuff for later use
tobuff(MAXIPbuff_rgl,MAXIPin_rgl,MAXIPout_rgl,SIBUFF,make8(Rxdata,0));
}
if (Rxdata & 0x4000L) // if TX buffer is empty (ready for a charcter)
{ // and there is a character to be sent
if (hasdata(MAXOPbuff_rgl,MAXOPin_rgl,MAXOPout_rgl,SOBUFF))
{ // send it
Rxdata = iSSPtransfer16(0x8000L | make16(0,ifrombuff(MAXOPbuff_rgl,MAXOPin_rgl,MAXOPout_rgl,SOBUFF)), RGL);
if (Rxdata & 0x8000L) // if there was a character returned from the tx
{ // put it in the MAXIPbuff for later use
tobuff(MAXIPbuff_rgl,MAXIPin_rgl,MAXIPout_rgl,SIBUFF,make8(Rxdata,0));
}
}
}
} while ((EXT2INT == 0) || (hasdata(MAXOPbuff_rgl,MAXOPin_rgl,MAXOPout_rgl,SOBUFF))); // loop for as long as the chip holds the interrupt line low
// this is necessary, since the Maxim device requires _level_ sensitive
// interrupt detection, but the PIC, is an edge sensitive device...
EXT2IF = 0; // clear the interrupt flag (releases the processor from ISR)
} |
So, I think I may be done.... again. |
|
 |
Ttelmah Guest
|
|
Posted: Fri Oct 19, 2007 2:22 am |
|
|
| jecottrell wrote: | Well, I guess I should Have checked this earlier. MAX3100 minimum clock timing is 100nS (from clock going from high to low or vice versa). I don't get above that (checked on the scope) until spi_clk_div_16. At that speed it's right about 200nS. However there is a 1500nS delay between the two bytes. (BTW it still fails at clk_16)
FWIW.
What I can't grasp is, why it would fail with a 'string' of characters, because the code handles each individually. It's got to be as Ttelmah says a problem within the register updates on the MAX3100. That's what I'm seeing at the point of failure when the IRQ is released prematurely. |
200nSec, is _still_ too fast for the MAX3100. It allows minimum clock 'high' time 100nSec, minimum clock 'low' time 100nSec, minimum _cycle_ 238nSec. This is why I said you needed to slow down the timings a lot....
I actually suspect, that most transactions in the chip, are quite happy at much faster timings, but possibly just one (the one enabling/disabling interrupts?) needs the extra time. It is suspiciously close to the timing that would be needed, if the chip needs one whole cycle of it's own master clock, after the interrupt bit is changed, before the transaction completes.
My own feeling is that because of the combination of the hardware fault in the 6627, and pushing the data too fast on the SPI bus, what is happening, is that the interrupt enable is on occassions getting missed by the chip.
On the 'polling' approach you how, it'll obviously work, but will slow the PIC terribly, if a lot of data is waiting to send. :-(
Best Wishes |
|
 |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Fri Oct 19, 2007 3:40 am |
|
|
This is what I saw on the scope (I probably didn't express clearly):
I'm not sure of the 'actual' timing based on 10MHz xtal and H4 fuse.
SPI full speed: 40nS/cycle or 20nS high/low time
div_4: 200nS/cycle or 100nS high/low time (closest to MAX3100 spec)
div_16: 800nS/cycle or 200nS high/low time (generously over spec) Still fails.
| Quote: | | the interrupt enable is on occasions getting missed by the chip. |
On the scope, if I'm seeing what I think I'm seeing, it looks as though the IRQ is enabled but releases almost immediately. (that is when it stops sending.)
OK. Now that you point it out, I see how I will hold in the ISR unnecessarily. I had another idea to recheck/confirm the 'interrupt enable' but I thought my first approach was more robust.(Maybe, but not very efficient.) Actually, now that you mention it and I look a little closer at how the ISR while loop is working, there maybe another thing or two to look at. I'll see if I can isolate the 'failure condition'.
I had another idea to move the TX control to a timer based system, but I can see that mixing the TX and RX in two different locations is asking for trouble, since it is quite likely that a character will arrive on a TX. (But I may still try and look into this further.)
I will work on the crystal you recommended for the PIC and the revised silicon part without the SSP errata. Hopefully that will narrow down the source of the problem.
Thanks for the continued dialog. I'm learning an incredible amount from this one problem and your sage advice.
John |
|
 |
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Fri Oct 19, 2007 12:25 pm |
|
|
Ever hear the story about the boy who cried wolf?
WOLF! WOLF! WOLF!
No, really I found it this time.
Once the loop that calls the maxputc function is done loading the buffer, it stops triggering the interrupt to transmit. I think that was your 'empty' code that you had?
So, now all I have to do is figure out the best way to continue activating the interrupt.
EDIT:
Based upon the fact that this is going to be a comm intensive application, I'm thinking about eliminating the activating/deactivating the TX interrupt on the MAX3100. The processor is tied up with all the comm overhead for the entire TX time. (i.e. there is no 'free' processor time while sending a long string of data.) When really, the required time to send a character for transmission should only take 20uS, not the back and forth for the full 180uS byte TX time at 57600 baud.
Planning on RX with your scheme (remove all the related TX stuff from the ISR.)
TX will be in a timer ISR @ 180uS. The timer will be activated in the maxputc and deactivated at the end of the ISR if isempty = TRUE.
Any comments or suggestions?
Thanks,
John |
|
 |
Ttelmah Guest
|
|
Posted: Fri Oct 19, 2007 3:31 pm |
|
|
Sounds a fair solution....
Best Wishes |
|
 |
|
|
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
|