| Author |
Message |
|
|
Posted: May 15, 2012 - 02:14 AM |
|

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 |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 03:57 AM |
|


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
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 05:07 AM |
|

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? |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 05:15 AM |
|


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
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 05:47 AM |
|

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 |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 05:59 AM |
|


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
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 07:09 AM |
|

Joined: Jan 21, 2012
Posts: 11
|
|
| Ok,I test on real hardware. please help me that show parameter in lcd. |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 08:18 AM |
|

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. |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 11:02 AM |
|

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 |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 11:11 AM |
|

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. |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 11:21 AM |
|

Joined: Jan 21, 2012
Posts: 11
|
|
|
|
|
|
|
Posted: May 15, 2012 - 11:40 AM |
|

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. |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 12:27 PM |
|

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 ! |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 12:44 PM |
|


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
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 02:30 PM |
|

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 ? |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 03:02 PM |
|

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. |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 03:19 PM |
|


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'. |
|
|
| |
|
|
|
|
|
Posted: May 15, 2012 - 03:36 PM |
|

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. |
|
|
| |
|
|
|
|
|