Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Oshonsoft with SPI device and Max7219/21

Status
Not open for further replies.
Hi,
This image using the Oshonsoft Breakpoint display, refer the 'sts' action.
A03.gif
 
I don't use Assembly Language, but after checking LDI and STS, it seems to be assigning 4 values to R16 then moving R16's contents to 4 sequential addresses?
I can't see how this helps. Ah! just been illuminated by my ignorance, I was thinking that .h was asm. I'll have to check if Eclipse generates ASM when it compiles.
A quick Google suggests the basic Arduino IDE doesn't

My question is, If I call an ASM routine, how do I get the variables out so that the BASIC program can use them.
E.g. if TempHum.asm communicates with the BME280 and generates variables called Temp and Hum. Are they in memory ready to go?
Is it just a case of knowing what they are called?
 
A quick Google suggests the basic Arduino IDE doesn't
hi,
Arduino does not create hex or asm files.

Oshonsoft does/can create asm, hex and lst files when it compiles a Basic program.

I will write up a simpler program to show the 'sts'.
Oshonsoft does shuffle the Basic and Asm code around in the list, it can be a little confusing.
E
 
hi,
Unzip this file, it is a Basic program and the output files.
The Oshonsoft Basic AVR, IMO is 'quirky', thats a technical for something that does not perform in a way, as I would expect.
I will do some more digging.
E

EDIT:
Found this link ref the AVR STS instruction.
https://www.codeproject.com/Articles/712610/AVR-Assembler
 

Attachments

  • sdzip1.zip
    1.8 KB · Views: 224
Last edited:
Hi
I'm not over keen on the Arduino IDE so I've been looking at Eclipse, after several hours I've given up on it, for me, much too complicated
After a 2nd attempt with Visual Studio Code, this time with Arduino extensions, I've managed to figure out most things.
The IDE can't find libraries yet when I try to debug, I just downloaded something library related, so I'll see what I've got another time.
The Keywords and #include autoprompts are just what I need to get started.

Ok back to your last 2 posts. The arduino does output .hex, the Arduino IDE for some odd reason stores it in AppData\Roaming\....
The version of Eclipse I was trying also saves a .h file. ASM is an output choice in one of its menus but it doesn't seem to make one.
So I doubt if I'll be coming up with any ASM code.

Just had a quick look at the .bas file. Won't that just keep overwriting r16 with the next variable ?
I did try ASM a long time ago with a Commodore 64, I think I managed to make a coloured pixel light up.
It seemed like an awful lot of work for not alot of action.

I've heard similar comments before about Oshonsoft code. Guess it's all down to individual style.
 
hi,
Are you using the Arduino on-line Editor or is the IDE installed in your PC.?
I don't have a Appdata\Roaming.

E
 
You will have to select "show hidden system files, folders and drives". I'm assuming you are using Windows.
If you look in the output console after selecting "Verify" it shows the exact path.
 
No hidden files on my PC, all viewable.
Full search of C drive for Appdata\Roaming, non found.
Full search for *.hex files, visible check shows no hex files with any of my Arduino Sketch named files.

Using Win XP Pro with Arduino 1.8.2 installed.

E
 
I'm using Windows 7. I've just had a look, Appdata doesn't seem to be used in XP. Also I got the folder wrong, there are 3 it's the Top one which is Local, the hex is stored in Temp.
They clearly don't want you to use it. Have you checked the console output after doing Verify? It might put something in Temp.
This HowTo shows how to make it happen. It also shows the directory path but it's to Appdata. Maybe it's possible to change the default path.
https://www.theengineeringprojects.com/2015/10/hex-file-arduino.html

Update 09/08/17

I wouldn't fret about not being able to find the hex, it doesn't work outside of Arduino.
There are 2 hex files, one has the project name the other is the same + include boot.
Using a 16mhz 328p in a PB + USPASP neither of them worked. I tried changing some fuse settings nothing. Which brings me to my next project: How to reset fuses on a dead AVR 328p :-(
It all went bad after Changing SUT = 11 to SUT = 00
Happy days!
 
Last edited:
Finally got around to trying the BME280 with Arduino. I can now see why Arduino is so popular, probably took less than 20 mins to set up the hardware and load a prepared sketch. Voila it works. Good news is my DIY 5v-3.3v level changer works fine. I only got Pressure and Humidity on the 16x2 LCD.
Took about another 20 minutes to figure out how to change Pressure to Temperature.
 
Last edited:
Good news for Oshonsofters, seems I was wrong about Oshonsoft not having the maths. All it needed was a 32 bit word (LONG).
I've now tested the Arduino with I2C and that works too, so I know my hardware works. I've also changed my mind about Arduino, once you get away from the "do it all for you programs" it's a bit of a nightmare. C might be flexible but IMO it makes for a very steep learning curve. At least I can now understand the structure and some of the code in C or Arduino.
Having reviewed several BME280 programs in C, python, Arduino and Bascom, the datasheet is making more sense.
I've also come to the conclusion that I2C is the way to go. Current experiment is to get the ID back from the BME280 using I2C.
So if you are intersted in using the BME 280 with Oshonsoft, watch this space.

Update 24/8
After several experiments with I2c and or SPI, I've now come to the conclusion that Hardware SPI is the way (as Ian Rogers said many posts ago).
I managed to get atmega328p working in Tx mode, only to have some sort of mishap with lost signature. This now happens with all 4 of my M328p so something odd going on. See new post in MicroC AVR.
I switched to PIC16F877A and after some head scratching and reading of both the datasheet (PIC16f886/7 is better) and other ppls code offerings I've got Hardware SPI in Tx mode using Oshonsoft PIC Basic. I'm hoping that Rx will follow today. If the number of views of this thread is any guide, many ppl are interested in hardware SPI so I'll post the code when it's complete.

I'm making progress with the BME280 too, I'll start a new thread when it's complete.
 
Last edited:
Hi Ian, Eric, John
I'm having trouble figuring out how to read/set the buffer full/overflow/SPI interupt on 16F877a. I had a similar problem with the atmega328p.
I found this code for Atmega328P, but it makes no sense to me. I tried to disassemble the code and sort of understand it but how to recreate it as Basic code is beyond me.
while (!(SPSR & (1<<SPIF)));
Code I've found for 16f877s is easier to understand a while loop around the interupt PIR1.sspif, but that just goes into an infinite loop.
Any ideas?
 
Morning Super'
The SSPCON1 register holds the SSPOV bit.
The SPSR is the 8 bit shift reg I/O reg.
The SPIF bit is in the PIR1 reg.

E

EDIT: The SSPIE is in the PIE1 reg
 
Morning Eric
Yes I know about the 2 registers and the (unmentioned) SSPIF and SSPIE. The registers are setup and work fine for sending but without any error handling e.g. collision detection, just a big enough delay for it to clear SSPBUF.
Other examples for SPI use the same settings. I just can't figure out how to tell if the Rx buffer (SSPBUF) is full by checking the interupt flag SSPIF.
I've found a couple of examples but they don't seem to work.
 
hi,
Rather than polling the SPIF, I would set the SSPIE and use an interrupt service routine to read the SPSR and then clear the SPIF.
As you say, if you poll a flag you could get locked in a wait forever loop, unless you enable an escape

E

EDIT:
Do you have a slightly bigger sample of your code that you post.?
 
Hi
So what am I looking for with SPSR, Buffer empty?
According to the DS, SSPIF is set when data is transferred from SPSR to SSPBUF, but how do I monitor SSPR? Is this the mysterious SSPCON2.
According to the DS SSPR is not directly accessable.
I'll have another look at what I did, maybe I was trying to set PIR1.PIF instead of PIR1.PIE
Read one (re)set the other? I think I might have been trying to reset PIF as in PIR1.PIF = 0

If that doesn't work I'll make up a doc with some of the examples I've found later today.
 
hi,
You don't monitor SPSR, the SPIF will be set when there is data in the SPSBUF, you read the SSPBUF, check the SSPOV to make sure there has been no SPSR overflow.
If no overflow, the data you have read from the SSBUF is valid, clear the SPIF flag.

If the SSPOV is set, then there has been an overflow of the SSPBUF, so the data is invalid, dump the read contents, clear the SSPOV and the SPIF flag

Await the next SPI interrupt.

E
A01.gif
 
Hi
Yep I got that, implimenting it is the problem. Also my BME280 has died :-( Just hooked it up to the Arduino dead as the proverbial duck.
I've modified my code to what I think might work.
The SUB waitrxflag: checks for interupt SSPIF
when it gets it SPI enable is turned off then back on to reset SPI
SSPBUF is reset by reading in "id = SSPBUF
Does this sound right?
I've attached the main code only for reference.
 

Attachments

  • SPI-BME.bas
    1.1 KB · Views: 240
hi S,
Looked over program, you are polling the SSPIF, this is not the way to go, use a Interrupt routine.
E
Clip from your listing:
waitrxflag:
While PIR1.SSPIF = 0 'wait for interupt flag
WaitUs 50
Wend
PIE1.SSPIE = 0 Disable spi
PIE1.SSPIE = 1 Enable spi
Return
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top