Thread: [Flashforth-devel] I2c using PIC MSSP
Brought to you by:
oh2aun
From: craig b. <dab...@ya...> - 2014-02-27 04:23:18
|
I'm coming back to FORTH after being away for a while including programming PIC16-s in assembler for a couple of decades. I've never really gotten the I2c mode of the MSSP module to work, I've always just fallen back on bit-banging a couple of I/O pins and been done with it. I now have a PIC18F4458 with FlashForth 3.8 up and ticking along on a 48Mhz oscillator with customized A/D routines to do 12-bit reads, and the included I2cBase routines loaded (tweaked for PortB SCL & SDA) because I also need to talk to ADS1100 I2c A/D converter chips. I don't actually have any I2c devices to talk to yet, but I have 10K pullups on the 2 pins and a BitScope attached to watch behavior. The I2cINIT, SSEN, and SPEN routines work as expected. I can even stick an i2c@nak in the middle and it runs straight through. What doesn't seem to work for me is the sspbuf! routine. I can't see any sign that pir1.sspif is ever changing after I clear it. The SCL pulses and data states for that one byte go out and then it just hangs. I have to ^O it to get out... which leaves little to diagnose with. the only thing that calls it and "works" is I2cWS which sits there madly banging the pins continuously untill I ^O that, too. Obviously I'm missing something, is it an I2c Slave on the bus? I won't get that for a day or more and if that's the problem, how can I test for that condition and keep running? I can still load up the FF Assembler and write yet another I2c bitbanger, but I was really hoping to get the hardware to work this time. If anyone can help point me in the right direction, I would be much obliged... Thanks for reading this, you're either very patient or completely bored (grin). craig bair ...averaging may or may not help clarify data. If Bill Gates walks into a bar, the average patron becomes a millionaire... |
From: Mikael N. <mik...@pp...> - 2014-02-27 05:37:15
|
When quickly checking the datasheet I saw no requirement for the slave to respond for sspif to be set. In the datasheet sspif is cleared after writing to sspbuf. In the current code sspif is cleared before writing to sspbuf. You could try this. : sspbuf! ( c -- ) \ sspbuf! takes 90 us @ 100 KHz sspbuf c! [ pir1 sspif a, bcf, ] [ begin, ] [ pir1 sspif a, btfss, ] [ again, ] ; Mikael |
From: Mikael N. <mik...@pp...> - 2014-02-28 05:57:47
|
If you want compiled code speeds, naturally you have to compile the code :-) There are some delays because the interpreter takes time to process the input line one word at a time. Another source of delay is if you have idle mode configured. In every PAUSE FF sleeps until the next interrupt. You can get rid off that by compiling FF with the idle mode disabled. The FF3.8 BUSY IDLE words are tricky to use, but are simplified in FF5.0 which you can find in GIT. I have not tried higher baudrates. Even if these could be configured, in practice the PIC18 cannot process data at those speeds. BR Mike On 02/28/2014 05:09 AM, craig bair wrote: > Sorry for the delay, things got crazed and I couldn't get back online > for a while there. > > As it turns out, putting the flag clearing after the buffer write > really did solve my problem, but there was this matter of scale with > the BitScope and its triggering. I'm guessing that there's some odd > interaction going on between some of the routines, the interpreter, > and the time-slicing of the multi-tasker. Entering the words as a > line interactively there was a 10 ms delay between the ssen and the > first sspbuf! with another 4 ms till the next sspbuf!. The little > pocket BS-10 wasn't retriggering on the second write leading to the > misinterpretation of events. It also wasn't happy about slowing down > enough to show the whole sequence, but eventually co-operated. > > Rolling the desired sequence together into a single word works much > more smoothly. Do interactive sessions often do this? I for one > normally wouldn't notice if it did under most circumstances. > > On an almost unrelated note, have you ever pushed a Pic18 UART to > 230.4K baud or 460.8K baud? I may have need to run that or higher > bit-rates between chips for a project and the numbers look like it > might be possible when clocking the pics at 48-64Mhz. One problem I > see is that I don't have a serial port that runs that fast to watch > them with. I hope that one of the FTDI usb-to-uart interface boards > can give me a virtual serial that can handle it, but I'm experimenting > blind at this point. Tera Term does have settings up to 921.6K, after > all....(grin) > > Keep up the good work! > craig > ...averaging may or may not help clarify data. > If Bill Gates walks into a bar, > the average patron becomes a millionaire... > > ------------------------------------------------------------------------ > ** > When quickly checking the datasheet I saw no requirement for the slave > to respond for sspif to be set. In the datasheet sspif is cleared after > writing to sspbuf. In the current code sspif is cleared before writing > to sspbuf. You could try this. : sspbuf! ( c -- ) \ sspbuf! takes 90 us > @ 100 KHz > sspbuf c! > [ pir1 sspif a, bcf, ] > [ begin, ] > [ pir1 sspif a, btfss, ] > [ again, ] > ; > Mikael > > |