SHIFTOUT problems on Atom 28 Pro

Hey guys. i’m new to this forum and especially new to these micro controllers and programming language, so i’m struggling a little bit :unamused:

in particular i am having trouble with the SHIFTOUT command as described in the 8000 manual. i’m trying to interface with a LCD that uses SPI serial communication. at the moment i have no idea if the problem is caused by the LCD, the micro or my crap programming skills. i’m using the ABB board with the Atom Pro 28, and the 20X4 LCD module from Modtronix. i was hoping if i post a bit of my code someone might be able to point out what i’m doing wrong.

[code]CS con P4 ;P4 - Chip Select, active low
CLK con P5 ;P5 - Clock
SPI_OUT con P6 ;P6 - Micro output/LCD Input Signal
SPI_IN con P7 ;P7 - Micro Input/LCD Output Signal

ant var byte
ant = “a”

low CS
shiftout SPI_OUT,CLK,msbpre,[ant\8]
high CS
pause 1[/code]

as far as i can tell everything is wried up correctly, but still nothing. does the SHIFTOUT command need some sort of initialisation?

this is a little off topic, but possibly related. i haven’t been able to get the DTMFOUT command working either. i’m using the on board speaker. my atom pro seems to have a white residue on it that looks kind of like flux, but i can’t be sure. is it possible there is a manufacturing fault that is causing the DTMFOUT and the SHIFTOUT not to work? i know from experience however that more likely than not its something i am doing wrong…

thanks in advance for your help guys,
Andrew,

I was just thinking that it might help to set the state of the clk pin before asserting the CS line… I am not sure how the BAP establishes the phase relationship between CLK and SDO/SDI so you may need to finagle with it to get the edges correct.

Alternatively you could bit bang the communication manually in a loop and prove out the rest of your hardware, then go back to figuring out the SHIFTOUT command.

bit bang sounds like a good place to start. not really familiar with this, but here is what i came up with. its pretty basic but should have worked i think, but didn’t…

[code]dirb = 15 ;set ports 4-7 as output

CS con P4 ;P4 - Chip Select, active low
CLK con P5 ;P5 - Clock
SPI_OUT con P6 ;P6 - Micro output/LCD Input Signal
SPI_IN con P7 ;P7 - Micro Input/LCD Output Signal

high CS ;Dissable CS

low CLK ;set clock starting position low
low CS ;enable writting to LCD
pause 2

;begin writting byte %10000001 (0x28)
high SPI_OUT ;bit7
pause 1
high CLK
pause 1
low SPI_OUT
pause 1
low CLK
pause 1

…and so on for the next 7 bits[/code]

and it doesn’t work! i think i’m going to need to get my hands on a cro. its a shame uni is finished for the year…

Hi klims,

Well I don’t have anything with an SPI port on it here at home to test with but I wrote the following and stepped through it with the debugger and it seems like it should work. Give it a try.

[code]
; written for BAP 8.0.1.3

; CS is on P4, active low
; CLK is on P5, init low, input latched on LE, output latched on TE
; SDO is on P6, latched on trailing edge of CLK
; SDI is on P7, latched on leading edge of CLK

sdobuf var byte
sdibuf var byte
lcv var byte
bitbuf var bit

; initialize the SPI bus
HIGH P4 ; CS = 1
LOW P5 ; CLK = 0
LOW P6 ; SDO = 0
bitbuf = IN7 ; ensure P7 is configured as an input
PAUSE 20 ; give a short delay

sdobuf = 0xF5 ; a reset command

; start of actual routine to bitbang an SPI port
BitBangedSPI:
LOW P4 ; assert CS
sdibuf = 0 ; set default received value

FOR lcv = 1 TO 8
IF (sdobuf & 0x80) <> 0 THEN ; set the output bit, MSB first
HIGH P6
ELSE
LOW P6
ENDIF

sdobuf = sdobuf * 2 ; left shift next bit into MSB position
sdibuf = sdibuf * 2 ; left shift sdibuf to make room for new bit

HIGH P5 ; CLK goes low to high
bitbuf = IN7 ; capture SDI state in bitbuf

; set the new bit in sdibuf if bitbuf <> 0, otherwise it defaults to zero
IF bitbuf = 1 THEN
sdibuf = sdibuf+1
ENDIF

LOW P5 ; set CLK low, this latches SDO on the peripheral
NEXT ; loop until we have sent all 8 bits

HIGH P4 ; return CS to inactive

; if this was a sub we would return here, sdobuf would = 0 and sdibuf would = received byte

END[/code]
I am also going to go out on a limb and say if it doesn’t work you might want to try a different set of port pins on the BAP. I seem to remember some of the pins are a little different, 3.3V in or out or something, but I never remember exactly what the deal was. I also know that I have some code for the PING)) sensor that works with some port pins and not with others so I am generally a bit suspicious when something seemingly simple and straight forward doesn’t do what it is supposed to.

good luck.

wow. thanks for the very comprehensive answer EddieB! unfortunately though it is still not communicating.

ok i think i see understand to a certain extent what you have done. it seems to follow the timing diagram that the manual shows. forum.modtronix.com/index.php?topic=399.0 this page shows the timing diagram and some code in C.
just as a matter of interest can the atom pro IDE handle C? i tried but it didn’t work.

i also tried your idea about different ports. i changed it to ports 0-3 and still nothing.

i must be doing something terribly wrong. it looks like i’m going to have to get a cro and analyse the signal.

thanks again for all the help,
Andrew.

You may want to step back and check some of the setup and electrical aspects. Have you tested the display using any other communications method to make sure that it works to begin with and to make sure that the commands being sent are proper? You should also probably double check that the display is configured for SPI on the DIP switch and that is has proper voltage and ground connections in addition to the SPI signals being correctly assigned. Not sure what else can be done to help from this end.

i have checked the hardware 100 times because that is usually where my mistakes are, but so far i have found no problem. with any luck i’ll be getting a cro this evening so i can check the output waveform. i hate when things don’t just work!

Not sure about the shiftout… Make sure the shorting bar is in place for the speaker enable. Also try a sound command instead of DTMF to see if it makes any sound.

It might help if we had a little additional information. Things like:

Which jumpers do you have installed on your ABB board?

When you power it up do you have a back light on your LCD or some type of logo that displays that gives you some indication that the LCD is working?

Which version of the IDE are you using?

I doubt that it would make a difference, but the SPI interface wants to output and input bits at the same time. So I wonder if you should make sure SPI_IN is in the input mode. (in SPI_IN)

I also could not tell from my quick look at the modtronix documention, what state the LCD comes up in. For example they do have commands for turning the display on and off, Does it default to on, or do you need to output the LCD on command? 0xf5 0x1a

Good Luck

Robot Dude - i’ve got the speaker making noise using the freqout command, but it won’t do it using the dtmfout command. it takes cpu time as though it was doing it which is the strangest thing about it.

i have finally got access to a cro so i’ll try to analyse the signal and see if i can find the problem. As for the little more information,

-i have the power jumpers installed giving the power rail regulated 5v.

-when powered up the initial display text comes up. i cannot confirm whether the backlight is on because i have nothing to compare it to. i got the LCD that has the black background with yellowish writing. my first impression though was that the backlight is on.

-the IDE version i am using is 08.0.1.0

like i said though i will try looking at the output on a cro and see what is being output, if anything at all.

thanks for the support guys,
Andrew.

I tested the DTMFOUT command and there are no errors, but it does not produce sound.
dtmfout 9,[1,2,3,4]

So I tested the DTMFOUT2 and got the following errors.
dtmfout2 9\10,[1,2,3,4]

C:\PROGRA~1\BASICM~3\BASICA~1\bin\hbasic.lib: Assembler messages:
C:\PROGRA~1\BASICM~3\BASICA~1\bin\hbasic.lib:9275: Error: Wrong size pointer register for architecture.
C:\PROGRA~1\BASICM~3\BASICA~1\bin\hbasic.lib:9275: Error: Bad expression
C:\PROGRA~1\BASICM~3\BASICA~1\bin\hbasic.lib:9275: Error: invalid operands
C:\PROGRA~1\BASICM~3\BASICA~1\bin\ld.exe : cannot open c:\files\basic atom\basic atom pro\dtmf.o: No such file or directory
Errors Detected

FREQOUT works.
freqout 9,1000,1500

SOUND works.
sound 9,[1000\1500]

SOUND2 does not work.
sound2 9\10,[1000\1500\1600]

C:\PROGRA~1\BASICM~3\BASICA~1\bin\hbasic.lib: Assembler messages:
C:\PROGRA~1\BASICM~3\BASICA~1\bin\hbasic.lib:9275: Error: Wrong size pointer register for architecture.
C:\PROGRA~1\BASICM~3\BASICA~1\bin\hbasic.lib:9275: Error: Bad expression
C:\PROGRA~1\BASICM~3\BASICA~1\bin\hbasic.lib:9275: Error: invalid operands
C:\PROGRA~1\BASICM~3\BASICA~1\bin\ld.exe : cannot open c:\files\basic atom\basic atom pro\dtmf.o: No such file or directory
Errors Detected

PWM works
pwm 9,20000,10000,1000

I tried HPWM. No errors but no sound.
hpwm 9,20000,10000

Is this a problem with the BAP?

No it’s a problem with the new IDE. I have emailed Nathan, he will look into it soon.

Ope! My bad :blush: . I tend to think problems are with the hardware when really its the software. This fix should allow me to write BAP code for my sound sensor which uses the SIFTOUT command for the ADC0832 chip. Infact, I was just reading the nuts-n-volt article about using the ADC0831 and the ADC0832.

You definitely need a scope for this. You also need to be sure you have everything set the way the devices datasheet says it needs to be. Some devices want a rising edge clock, some a falling. Some want data MSB some LSB. There are a lot of variables. your above code isn’t taking into account.

P6 and P7 are the 3.3v only pins on the BAP. I would recommend you use different pins unless you KNOW your dives works with 3.3v. Most do but it’s a possible cause of problems that you don’t NEED to deal with.

What are you using that has an onboard speaker? Sorry if I missed it in an earlier post. If you mean the buzzer on the ABB, that isn’t a speak IIRC. It’s just a buzzer. Jim can confirm or deny this. Also the DTMF(not DTMF2) has to have a good fileter on it or you just get noise. The filter will take the digital pulses and smooth them out into something resembling a sin wave(two sin waves actually). A note on DTMF2. it produces sound via simple square waves. It also must have a good filter to get something resembling a sin wave or most devies will NOT “understand” it. DTMF actually produces a better signal as far as “understaniong” it is concerened but it tends to be very low volume where DTMF2 can produce very loud sounds.

Please post two simple programs. One with DTMF showing that problem(eg no sound) and one with DTMF2 showing it’s problem. If you like just email me the code([email protected]). I’ll run tests on them and fix it ASAP.

Yeah it actually has a piezo speaker. :wink:

A temorary workaround for DTMF(not DMTF2 which appears to be working correctly in the BETA version of the IDE, not 8.0.1.0) is to use FreqOut instead with the correct frequencies. Below is a list of the dual tone frequencies for DTMF in HZ:

[code]
Button freq1 freq2
1 697 1209
2 697 1336
3 697 1477
A 697 1633
4 770 1209
5 770 1336
6 770 1477
B 770 1633
7 852 1209
8 852 1336
9 852 1477
C 852 1633

  •   941		1209
    

0 941 1336

941 1477

D 941 1633[/code]