Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problems with SPI communication using Atmega8, Please help

Status
Not open for further replies.

cerberolooch

Newbie level 2
Joined
Apr 13, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Ecuador
Activity points
1,333
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:
$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 "komodo"
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
 

Re: Problems with SPI communication using Atmega8, Please he

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.
 

Hello Cerberolooch,

Sorry for the late response. i have been busy with my other projects and had no time to see my messages.

Oh yes, i have just checked my earlier post and that problem i had faced before with MEGA8. You can fix that problem to calibrate the oscillator of the MEGA8. If you are using BASCOM then try to do OSSCAL test.

For example: i have tried that OSSCAL test and got the correct value 171 - 180. so in the starting of my BASCOM program i put the line OSSCAL = 171.

Remember, the OSSCAL value is from 0 - 255 . you can try this test like this:


OSSCAL = 171

Print "OSC TEST" < --------- if it will print correctly to the Hyperterminal then value is ok. otherwise use another value or try with FOR NEXT LOOP .

i hope it would be helpful to yo .

Regards,
Shan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top