Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
saeidhp
PostPosted: May 15, 2012 - 02:14 AM
Newbie


Joined: Jan 21, 2012
Posts: 11


Hi
I want read from mcp3909 through Spi in codevision

Code:


#include <mega32.h>
#asm
   .equ __lcd_port=0x1B ;PORTA
#endasm
#include <lcd.h>
#include <spi.h>
#include <stdlib.h>
char data_get[10];
void main(void)
{
PORTB=0x00;
DDRB=0xB0;
SPCR=0X50;
SPSR=0x00;
lcd_init(16);
PORTB.0=0;
spi('R');
spi('X');
spi('D');
spi('4');
data_get[0]=spi('R');
data_get[1]=spi('O');
data_get[2]=spi('D');
data_get[3]=spi('4');

while (1)     
      {
       
      };
}

When I send one character for example R , program work correctly (I test with spi debugger in proteus)but when send more than one character in spi debugger has error
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: May 15, 2012 - 03:57 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 20381
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

What happens with REAL HARDWARE?

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
saeidhp
PostPosted: May 15, 2012 - 05:07 AM
Newbie


Joined: Jan 21, 2012
Posts: 11


I don't test with real hardware because my program in spi debugger is not correct.

Did you see any problem in my program?
 
 View user's profile Send private message  
Reply with quote Back to top
larryvc
PostPosted: May 15, 2012 - 05:15 AM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

saeidhp wrote:
I don't test with real hardware because my program in spi debugger is not correct.

Did you see any problem in my program?


Perhaps the debugger is incorrect.

Yes, I see that you did not test it on real hardware.

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
saeidhp
PostPosted: May 15, 2012 - 05:47 AM
Newbie


Joined: Jan 21, 2012
Posts: 11


When I Send one character for example just R
the spi debugger work correctly and show 110100 Bin = 34 Hex

but when send more than one character just the last character convert correctly.

see the picture
 
 View user's profile Send private message  
Reply with quote Back to top
larryvc
PostPosted: May 15, 2012 - 05:59 AM
Raving lunatic


Joined: Dec 06, 2007
Posts: 2512
Location: Redmond, WA USA

Do you understand what we have been telling you?

Until you run your code on real hardware you will not know if it is the debugger that is wrong or your code that is wrong.

Run the code on real hardware, not in Proteus.

I'm sorry but I have an aversion to helping people that are using Proteus. Someone else will have to help you.

Good luck.

_________________
Larry

Those afraid to embrace the future will quickly fade into the past. - larryvc
 
 View user's profile Send private message  
Reply with quote Back to top
saeidhp
PostPosted: May 15, 2012 - 07:09 AM
Newbie


Joined: Jan 21, 2012
Posts: 11


Ok,I test on real hardware. please help me that show parameter in lcd.
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: May 15, 2012 - 08:18 AM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16320
Location: Wormshill, England

The MCP3909 is "Energy Metering IC with SPI Interface and Active Power Pulse Output"

From a brief glance at the data sheet, I do not recognise SPI commands like R,X,D,4

You do not say which pin is connected to /CS. You would normally take /CS low at the beginning of a command and high at the end.

I am quite happy to assist with your Proteus simulation. Just quote your license number (or school)

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
saeidhp
PostPosted: May 15, 2012 - 11:02 AM
Newbie


Joined: Jan 21, 2012
Posts: 11


plaese see this picture
of course I writed part of register

whole register is R0D406X

please check your private message
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: May 15, 2012 - 11:11 AM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16320
Location: Wormshill, England

From the MCP3909 data sheet (22025a.pdf):
Quote:
FIGURE 4-2: SINC Filter Magnitude
Response (MCLK = 3.58 MHz).


Perhaps you have a different data sheet.

We will help you with real hardware.
We will not help you with cracked Proteus.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
saeidhp
PostPosted: May 15, 2012 - 11:21 AM
Newbie


Joined: Jan 21, 2012
Posts: 11


Oh yes this page is from MCP3909 and PIC18F85J90 Single phase Energy Meter Reference Design
page 32.

http://ww1.microchip.com/downloads/en/D ... 51884a.pdf
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: May 15, 2012 - 11:40 AM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16320
Location: Wormshill, England

As far as I can see, the reference design uses a Microchip MCU to follow a protocol.

The actual measuring work may be done with the MCP3909 but the MCU converts it into useful information.

I am sure that you could equally well use an AVR. You just need to write equivalent firmware.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
saeidhp
PostPosted: May 15, 2012 - 12:27 PM
Newbie


Joined: Jan 21, 2012
Posts: 11


I don't understand exactly.
it means this page just for Microchip MCU and my codes Are wrong ?
please help me !
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: May 15, 2012 - 12:44 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21271
Location: Orlando Florida

Which city and state in the United States do you live? There might be other AVRfreaks near you.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
saeidhp
PostPosted: May 15, 2012 - 02:30 PM
Newbie


Joined: Jan 21, 2012
Posts: 11


I don't live in the United States.

I just help about my codes.

there aren't any problem in my Codes?

Do you have any codes about SPI in Codevision ?
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: May 15, 2012 - 03:02 PM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16320
Location: Wormshill, England

SPI in CodeVision works exactly the same as with any other compiler or MCU. e.g. assert ChipSelect, transfer several SPI bytes, de-assert ChipSelect.

If you have a MCP3909 and no PIC18F85J90, you have to control your MCP3909 by yourself.

It is a reference design, so I presume Microchip supply the C source code. You just need to rewrite it for an AVR. An AVR can do much the same things as a P*C.

No. I have only briefly glanced at the application note and chip data sheet.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
theusch
PostPosted: May 15, 2012 - 03:19 PM
10k+ Postman


Joined: Feb 19, 2001
Posts: 25921
Location: Wisconsin USA

Quote:

When I Send one character for example just R
the spi debugger work correctly and show 110100 Bin = 34 Hex

Ummm--0x34 is '4', not 'R'.
 
 View user's profile Send private message  
Reply with quote Back to top
saeidhp
PostPosted: May 15, 2012 - 03:36 PM
Newbie


Joined: Jan 21, 2012
Posts: 11


Quote:
Ummm--0x34 is '4', not 'R'.


Yes you say right 'R'=0x52.

Excuse me, at the last example I sent '4' not 'R'.

You can't help me too?

I need an example in codevision that read from SPI.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits