2

Author Topic: Problems with SPI communication using Atmega8.  (Read 5116 times)

0 Members and 1 Guest are viewing this topic.

Offline cerberoTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Problems with SPI communication using Atmega8.
« on: April 29, 2010, 06:27:11 PM »
Hi, how’s going. I’ve a really big problem with the SPI communication. I’m using the atmega8, I’ve tried to use atmega48 but I don’t know way but even the simulation doesn’t work at all.

I’m programming on Bascom. So far the simulation, which I’ve been doing it on Proteus(ISIS), works perfectly, but once I try on hardware it doesn’t work.

I’ve checked about the fuse bits for programming, and it looks like is ok. I had used extreme burner and progisp in order to program the mu. But there is always the same mistake (there is not SPI communication, no even the signals on miso, mosi, sck,etc, im using a oscilloscope to see that).

Here I left my testing code (on bascom), please check it and tell me if something is wrong.
Something about I’m starting to doubt about is, if it’s ok to use the hardware SPI communication, ‘cause its use to program the mu. Please help.

A really important Question, if I´m using my mU as a master, doesn’t matter if it is or not connected with a slave or other spi devise, it should have and show the miso, mosi, sck signals, isn’t it?

If somebody wants more info about the program I’d send u my testing program, simulation on ISIS, please check it and if u find something wrong please let me know
PD: the project in the future has to use this communication with the ADE7758 and with a WIFI module, so the most important by now is to have the spi communication.
Code: [Select]
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim A As Byte , S As String * 3 , Addresset(9) As Byte , Readdata(14) As Byte , Meter As Bit , Wifi As Bit
Dim Addresdat(5) As String * 4 , Valor(5) As String * 1
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1 ', SPIIN=value
Ddrb.2 = 1
Ddrb.1 = 1
'Config Portb.1 = Output
'Config Portb.2 = Output

Addresset(1) = &H93 'address de OPMODE (ojo ya esta con el MCB en 1 para escritura a esta address, original h13) a ser seteada, ojo la direccion de WAVMODE es 0x15 pero la voy a dejar con del set default
Addresset(2) = &H00 'Valor de OPMODE a ser seteado
Addresset(3) = &H94 'address de MMODE (ojo ya esta con el MCB en 1 para escritura a esta address, origina h14)a ser seteada, ojo la direccion de COMPMODE es 0x16 pero la voy a dejar con del set default
Addresset(4) = &H04 'Valor de MMODE a ser seteado
Addresset(5) = &HA3 'address de GAIN (ojo ya esta con el MCB en 1 para escritura a esta address, original h23)a ser seteada,esta dierccion posee los valoers de ganacia y escala de I y V en al PGA ojo la direccion de LCYCMODE es 0x17 pero la voy a dejar con del set default
Addresset(6) = &H40 'Valor de OPMODE a ser seteado
Addresset(7) = &H13
Addresset(Cool = &H14
Addresset(9) = &H23


Prob:
Wait 1
Set Portb.1
Set Portb.2

Display On
Cls
Lcd "Luis Mena"
Locate 2 , 4 : Lcd "Poli"
Wait 2
For A = 1 To 10
Shiftlcd Right 'shift the text to the right
Wait 1 'wait a moment
Next
Spiinit
Reset Portb.2
Spiout Addresset(7) , 1
Set Portb.2
Reset Portb.2
Spiin Readdata(1) , 1
Set Portb.2
Waitms 100
Set Portb.2
Spiout Addresset(Cool , 1
Set Portb.2
Reset Portb.2
Spiin Readdata(2) , 1
Set Portb.2
Reset Portb.2
Spiout Addresset(9) , 1
Set Portb.2
Reset Portb.2
Waitms 1
Set Portb.2
Reset Portb.2
Spiin Readdata(3) , 1
Set Portb.2
Reset Portb.2
Spiout Addresset(7) , 1
Set Portb.2
Reset Portb.2
Spiin Readdata(4) , 1
Set Portb.2
Cls
For A = 1 To 4
Addresdat(a) = Hex(readdata(a))
Valor(a) = Str(a)
Locate A , 2 : Lcd "Valor"
Lcd Valor(a)
Lcd Addresdat(a)
Wait 1
Next A
Wait 10
Cls
Locate 1 , 4 : Lcd "Pruebas"
S = Str(a)
Lcd S
Wait 3
'Spiinit
Spiout Addresset(1) , 6
Spiout Addresset(7) , 1
Waitms 1
Spiin Readdata(1) , 1
Waitms 1
Spiout Addresset(Cool , 1
Spiin Readdata(2) , 1
Spiout Addresset(9) , 1
Waitms 1
Spiin Readdata(3) , 1
Waitms 1
Spiout Addresset(7) , 1
Spiin Readdata(4) , 1
Cls
For A = 1 To 4
Addresdat(a) = Hex(readdata(a))
Valor(a) = Str(a)
Locate A , 2 : Lcd "Valor"
Lcd Valor(a)
Lcd Addresdat(a)
Wait 1
Next A
Wait 10
Goto Prob

« Last Edit: April 29, 2010, 06:42:40 PM by cerbero »
thanks,gracias,dank,merci

Offline dunk

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 1,086
  • Helpful? 21
Re: Problems with SPI communication using Atmega8.
« Reply #1 on: April 30, 2010, 02:57:00 AM »
i don't know anything about Basecom so i'm afraid your code is meaningless to me.

Quote
A really important Question, if I´m using my mU as a master, doesn’t matter if it is or not connected with a slave or other spi devise, it should have and show the miso, mosi, sck signals, isn’t it?
correct.
you should see a signal on the clock and MOSI lines.

Quote
Something about I’m starting to doubt about is, if it’s ok to use the hardware SPI communication, ‘cause its use to program the mu. Please help.
it would be worth unplugging your hardware programmer before you test the clock and MOSI lines.


dunk.

Offline TrickyNekro

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,208
  • Helpful? 15
  • 1.6L Peugeot 307 tuner
Re: Problems with SPI communication using Atmega8.
« Reply #2 on: April 30, 2010, 05:33:20 AM »
That's why I hate Bascom and turned to C...

Well.... To start debugging the whole thing, first thing I would do is to doubt the
Bascom ability to set the Hardware SPI as I like...
Look at the Datasheet of the microcontroller and try to set the SPI by hand.
What I mean is that for first step try to write directly at the registers.

If your code is correct, you should get some signals out of it...


I expect that you know how to read a datasheet...

Best Regards, Lefteris
Greece
For whom the interrupts toll...


P.S. I've been inactive for almost a year... Don't give promises but I'll try to complete my tutorials. I'll let you know when..

Cheers!

Offline cerberoTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: Problems with SPI communication using Atmega8.
« Reply #3 on: April 30, 2010, 05:52:28 AM »
hi thanks for answering some of my questions, I chose Bascom 'couse is kind of easier. And being this my first time using AVR, I suposed it will be faster and easier. So i think i'll migrate to como C compiler, any advise. on the other hand about reading the Satasheet, i've already done, however now im cheking the Lock-bits part, i think it could be the problem. If someone could sendme some example of fuse and lock settings , that would be great.
thanks,gracias,dank,merci

Offline cerberoTopic starter

  • Beginner
  • *
  • Posts: 4
  • Helpful? 0
Re: Problems with SPI communication using Atmega8.
« Reply #4 on: April 30, 2010, 10:33:02 AM »
Based on some common questions that I’ve found in some forums, I will try to post as much info that could be useful for some people and also will help somebody in order to identify the problem and help me.

1- I’m posting my test code with some comments to know what are and way I’m doing some code lines.
2- I will post the schematic that I’m using to test in Proteus; it’s basically the same that’s in hardware.
3- I’ll post, how the fuse and lock-bits config has been done.(I’m posting the config used in WINPIC800, it’s the same that I’m using in extreme burner and progisp. None of this works on hardware)

Some important answers for some common questions.

1.- I’m using ATmega8, the slaves devises will be a Wifi module and the ade7758, both need or will need SPI communication to work in future. I have 3 atmega8 I’ve tried with all of them the same result(no spi communication, no spi wave forms on sck, miso, mosi, that had been checked with an oscilloscope)
2.- On hardware, the LCD is connected and working, so it means the atmega is ok (with one of them y had a slower presentation and function, it looks like a fuse problem but I haven’t checked and changed yet).
3.- The Spi wires are around 5-7 cm long (2-2.5 inches). Even plugging the oscilloscope right with the atmega pins, I got nothing.
4.- the power source (5V), it working fine, double and triple checked. I’ve even used in other project and works fine.

---------------
Some questions from me.
I’ve found some posts about problems with Bascom, so I’ll change to C, however, there must be a way to fix this problems, so I’d really love if somebody could help me and fix this problem, but I’m kind in a hurry with this project so I will start to do it in C or C++. I have already download IAR Embedded Workbench for Atmel AVR 5.20 and I’m downloading codevision (please as I have already told u is my first time with Atmel-AVR and I’m a little bit lost and dissipate). So if somebody could help me advising me a good compiler and some code examples will be great.
Thanks.
I’ve found a comment in a forum abut a problem With Proteus, and that’s the reason way the SPi works there, can somebody tell mi way.

PD: i’ll upload some info if it’s allowed. Please check it.
thanks,gracias,dank,merci

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
Re: Problems with SPI communication using Atmega8.
« Reply #5 on: May 01, 2010, 12:03:07 PM »
Sorry, but I am afraid I can't help you with SPI. I am using Arduino, because it has lots of ready made libraries for anything I need to do, so all I have to do is link the library, learn the proper commands to use it and do my thing with it. I remember seeing some posts on Arduino Forum about WiFi and that ADE7758. Just go there and do a search and you'll find your answers. Good luck!
Check out the uBotino robot controller!

 


Get Your Ad Here