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.

Superdat

Member
Hi
I've decided to have a go at programming a BME 280 Humidity and Temperature sensor. It has both I2C and SPI interfaces.
So far I've only used SPI with any success, although I didn't make a good choice of hardware for my the one attempt with I2C.
I've only used SPI with MAX7219/21 so the use of Slave Select (CS) was handled by Oshonsoft.

After some research I've come to the conclusion that I need a SS for each ISP device. In this case one for Max7221 and one for the BME 280.
Is this correct?
I'm aware that Oshonsoft uses software SPI.
I can't see any reference to an address for the Max7221 device. The only address I can find are to registers or banks of Max7221.

Is it possible to use Oshonsoft to control both devices or have I got to use Hardware SPI?
 
OK
Thanks, I had a suspicion that was what was needed.
At least now I won't be wasting time trying to get something to work that can't. "Where does that boy get all these words from?" :)
I've got what I think is a good BASIC example from the GCB forum, I'll see how I get on with that.

Am I correct about one Slave Select per device?
 
I've had a look at the afore mentioned program and it's a bit of a B****** Muddle. Very difficult to understand mainly because Commands/Functions listed in the Program don't exist etc.
I've also had a look at the data sheet for mega328P and it looks.....complex.
I think I might see if I can get the BME 280 to work with I2C first.
Presumably I can still use SPI to drive the Max7221?

Had another look at the datasheet, as usual it makes more sense this time so I'll have a go at SPI.

One thing I spotted is mention of Offset when loading data.
Anyone know what this means? It was referred to when using Assembler. I'm hoping to be able to do a combination of Basic and Direct Addressing. Assembly is not one of my skills.
 
Last edited:
Update
After spending time browsing through Atmega328P and BME280 datasheets plus any coding examples I could find for BME280 in any programming language.
I've come to the following conclusions.
For a temp/humidity sensor BME280 is a very complicated beast. I'm not sure which is the hardest to understand, the German-English translation of the BME280 DS or the Techno-English of the Atmega328P. The only complete source code examples I can find are in Python or "C".
I've also realised that because of a limitation in its math capability, Osonsoft cannot do some of the calculations.
I "fixed" the Atmega problem by setting up Oshonsoft to the lcd and the BME by SPI. Both of which I've used sucessfully.

So at the moment I have an ATmega Dev board connected to an HD47780 and a DIY bidirectional 5v to 3.3v level changer which has a BME280 breakout board nestling in the centre. Apart from checking that 5v does convert to 3.3v and visa versa the hardware may or may not work OK. I just get a return of FF i.e. signal permanetly high so most likely nothing.
All things taken into consideration I'd say my chances of getting this working are akin to a snowball's chance in hell!

With some reluctance I've decided I need to learn "C", but that's not going to help with all the other stuff. If I can't understand how the BME280 works it matters not if I can program in "A", "B" or "C". A cunning plan (I hope) as emerged.

There's lots of support for BME280 on the Arduino, the down side is that most of the support comes as a library. Arduino is sort of like "C" and can be programmed with the later.

I've ordered an Arduino! The rational is as follows:
Hopefully I can get the software working fairly easily with half a dozen or so #includes. I can use this to see if the hardware is OK.
Once everything is working, I can reverse engineer the arduino into "C". I learn much better working on a real example with known inputs and outputs.
Some examples I've seen (maybe many examples is better) are so abstract or clever that I can't understand what it's trying to do let alone understand the example.
I'm afraid Oshonsoft is guilty of this frequently.

I've already figured out how to flash an LED (sorry officer I won't do it again), using my own code with Arduino, next I'll try doing the same in "C".
I found AVR Studio 7 so complicated and enormous that I've uninstalled it and gone with WinAVR. It's very basic but as a result IMO is much easier to work with too.
So the Arduino should be here today, just can't wait to get that LED flashing. :)
 
hi Super,
The Arduino IDE comes with a Blink Sketch, so you should get the onboard LED flash running OK.

Tip:
if the Sketch you are working refuses to load into the Atmeg, use compile/load the Basic/Bare Minimum Sketch, in Examples to regain control.
also when using UART receive On Event, insert a simple switch between the incoming RXD line and the Arduino, open the switch when compile/loading, to disable the On Event call.

E
 
I just took a peek at the BME280 datasheet. It is crafted along the same lines as the Bosch DS for its e-compass/accelerometer, like the BMC156. The only problem that device gave me was the sleep mode, which is default. I needed to keep waking it after each read, which I discovered during simulation and not from reading the DS. It might be there; I just didn't see it.

Bosch also has the habit of referring to bits within a byte based on the function. For example, of you look at a register map, you will find bit<0> might have a function such as "self test" and bits<2:1> may be "op mode." In describing op-mode, however, Bosch refers to those bits as bits <1:0> . Not really a problem once you see the logic, but something to be aware of

John
 
I just took a peek at the BME280 datasheet. It is crafted along the same lines as the Bosch DS for its e-compass/accelerometer, like the BMC156. The only problem that device gave me was the sleep mode, which is default. I needed to keep waking it after each read, which I discovered during simulation and not from reading the DS. It might be there; I just didn't see it.

Bosch also has the habit of referring to bits within a byte based on the function. For example, of you look at a register map, you will find bit<0> might have a function such as "self test" and bits<2:1> may be "op mode." In describing op-mode, however, Bosch refers to those bits as bits <1:0> . Not really a problem once you see the logic, but something to be aware of

John
Thanks, I'll keep that in mind when I eventually get there! It sounds a bit like the way they use bit 7 to indicate read or write then use bit 6 as if it was bit 7 or did I get that wrong?
 
hi Super,
The Arduino IDE comes with a Blink Sketch, so you should get the onboard LED flash running OK.

Tip:
if the Sketch you are working refuses to load into the Atmeg, use compile/load the Basic/Bare Minimum Sketch, in Examples to regain control.
also when using UART receive On Event, insert a simple switch between the incoming RXD line and the Arduino, open the switch when compile/loading, to disable the On Event call.

E
When I said I'd got my own code for a blinking LED, I should have said, an LED on pins of my choice rather than the onboard one + plus a switch to turn the LED on or off.
The onboard LED has a totally unique bit of code which is OK to get going but somewhat restricting + I'm pretty sure it won't convert into "C".
If pinmode 2 = High
onboard LED = HIGH, (or something like that, the Arduino compiler is on a different PC)
Humm I think it might need a bit more info lol.
I'm to familiar with addressing a port directly, so using a magic commands goes against the grain.
It will be fine to see if the BMP works, then at least I'll know that the hardware is OK.
There's certain things I'm happy to have done for me, e.g. I can't see any point is figuring out all the codes to address the HD47780.
I just use the built in Oshonsoft routines, so I don't have an issue with using #include lcd.h or what ever it's called.
I'm too old to learn everything! I need to use my time wisely, about time too ;-)
 
Here's a snippet of a register map from the BMC156:
upload_2017-8-2_6-52-9.png


Register = 0x4C, default value = 0x06. It is 8-bit with MSB on the left. The DS refers to each function, e.g., Data Rate or Opmode, as bits <2:0> and <1:0> ,respectively. Once you realize it is referring only to that portion of the byte there is no confusion. However, early on I was writing some code looking only at the section of the DS dealing with register 0x4C and op-mode. I ended up having to shift the value left when I looked at the whole register map, which was virtually unreadable on my screen. I mentioned not as an error but as something to be aware of.
 
I don't think Bosch had hobbyists in mind when they designed these products! I guess it's not too far away from what the MicroCs do using bits of register bytes to configure stuff, just a different way of explaining it.
Not sure where I got the idea from, but I just spent the evening installing Eclipse with AVR and Arduino plugins. Took awhile to figure out how to open an Arduino project/file (import not open).
The program is a bit slow to load but is awesome, I love the way it prompts for missing syntax.
 
I don't think Bosch had hobbyists in mind when they designed these products!

It is the same with programming complexity of the Bosch BMP180 barometric pressure sensor
 
While exploring things Arduino, I just realised I already had one but I call mine an Atmega328P project board and a usbasp programmer. You live and learn {if you're lucky}. Notice the squiggly backets? Thought I'd practice some "C". ;-)
 
hi,
The tech term for squiggly brackets is curly braces.:woot:

E
 
The board arrived yesterday, I didn't go for the cheapest nor the most expensive, it claims to be made in Italy. I'm reasonably sure it's not an original.
I've spent quite alot of time trying to set up Eclipse. Not sure if it was me (I didn't really know what I was doing at times), I had problems mainly with Oxygen plugins.
Finding the "hidden" bits needed to make the Uno go were also a bit of a challenge. Theres an awful lot of stuff that isn't relevant.
I eventually tried Neon and I've got that working with C and Arduino plugin. Still can't get auto suggestion to work but parentheses highlighting is good.
I'm also questioning my thoughts about learning "C". All I'm really trying to do, is get the BME 280 working. Now that I've discovered that Arduino also generates non bootlader code, I might see if I can get Oshonsoft to work with come compiled code from the arduino. If I can, I'll post it. See back on track for this forum! :)
I'm now sufficiently interested in "C" to have a dabble.
Question are [] brackets called stretched braces? ;-)
 
Question are [] brackets called stretched braces? ;-)
Morning SD,
Square brackets seems to be the flavour of choice.

As Shakespeare said about the bow legged man.
What manner of man is this, who carries his ba**s in parenthesis.

If I can help with Oshonsoft just ask.
BTW: Don't forget you can use some Asm code fragments in your Basic coding.

E
 
Last edited:
Morning SD,
Square brackets seems to be the flavour of choice.

As Shakespeare said about the bow legged man.
What manner of man is this, who carries his ba**s in parenthesis.

If I can help with Oshonsoft just ask.
BTW: Don't forget you can use some Asm code fragments in your Basic coding.

E
Hi E
Yes I know about including ASM in Oshonsoft, I've only used it for Direct Addressing. If I can get it to work it might be a nice gift to Oshonsoft AVR users.
If I can get the arduino to do what I want but have trouble porting it across, I will ask for your assistance.
Am I right in thinking that (init "new ASM code name" ) is how the ASM is started by Oshonsoft AVR?
Square brackets would have been my first choice, just thought stretched braces was slightly more amusing ;-)
 
hi SD,
You can either use the IncludeASM "Your1.asm" or insert lines of code, starting with ASM: [ I prefer the latter]
If "Your1.asm" is not in the same folder as the Basic code, add the path to the Include.

This is a demo4.bas for demo only for ASM examples.

E
 

Attachments

  • demo4.bas
    1.6 KB · Views: 255
Thanks, I haven't used this before, just remembered earlier, for direct addressing you just use the keyword e.g. ADCON = 1
So in this line
ASM: sts varname,r16

Is that saying run ASM file "sts" and use the variable "r16" for its output?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top