Hello;
I am new to ARM. i am using LPC2119 development board. i need to send a array of
hexadecimal value serially to a GPIO. in simpler way is i need to interface
74hc595 shift register to ARM. i dont want to interface with SPI, i need to do
it manually using GPIO.
I did some programming but it shows error. I use Keil uvision, realview
compiler. Here the program.
#include
#define Data_Pin (1 << 21)
#define Data_DIR_SET (IO0DIR |= Data_Pin)
#define Clock (1 << 22)
#define Clock_DIR_SET (IO0DIR |= Clock)
#define Clock_SET (IO0SET = Clock)
#define Clock_CLR (IO0CLR = Clock)
#define Latch (1 << 23)
#define Latch_DIR_SET (IO0DIR |= Latch)
#define Latch_SET (IO0SET = Latch)
#define Latch_CLR (IO0CLR = Latch)
int bu[]={0x00,0x1E,0xff,0xfe};
void shift_595(int buff)
{
Clock_CLR;
Latch_CLR;
Data_Pin=buff;
Clock_SET;
Clock_CLR;
}
int main(void)
{
int loop;
while(1){
for(loop=0;loop<8;loop++){
shift_595(bu[loop]);
}
}
}
Error is :main.c(23): error: #137: expression must be a modifiable lvalue
error is pointed t Data_pin=buff;
please find what mistake i did and guide me.
Loading data serially on a GPIO pin.
Started by ●December 23, 2010
Reply by ●December 23, 20102010-12-23
On 12/23/2010 07:16 AM, Dhinesh wrote:
> #define Data_Pin (1 << 21)
>
> Error is :main.c(23): error: #137: expression must be a modifiable lvalue
> error is pointed t Data_pin=buff;
Try to think how it is after macro expansion:
(1 << 21)=buff;
What does that mean?
--
Timo
> #define Data_Pin (1 << 21)
>
> Error is :main.c(23): error: #137: expression must be a modifiable lvalue
> error is pointed t Data_pin=buff;
Try to think how it is after macro expansion:
(1 << 21)=buff;
What does that mean?
--
Timo
Reply by ●December 23, 20102010-12-23
Thanks for reply,
That's wrong, but i need to load data to particular pin so that i reffered to (1<<21), thats wrong i too know. please provide the solution. I could have used IOPIN0 register, but that wont work.
--- In l..., Timo wrote:
>
> On 12/23/2010 07:16 AM, Dhinesh wrote:
> > #define Data_Pin (1 << 21)
> >
> > Error is :main.c(23): error: #137: expression must be a modifiable lvalue
> > error is pointed t Data_pin=buff;
>
> Try to think how it is after macro expansion:
>
> (1 << 21)=buff;
>
> What does that mean?
>
> --
>
> Timo
>
That's wrong, but i need to load data to particular pin so that i reffered to (1<<21), thats wrong i too know. please provide the solution. I could have used IOPIN0 register, but that wont work.
--- In l..., Timo wrote:
>
> On 12/23/2010 07:16 AM, Dhinesh wrote:
> > #define Data_Pin (1 << 21)
> >
> > Error is :main.c(23): error: #137: expression must be a modifiable lvalue
> > error is pointed t Data_pin=buff;
>
> Try to think how it is after macro expansion:
>
> (1 << 21)=buff;
>
> What does that mean?
>
> --
>
> Timo
>
Reply by ●December 23, 20102010-12-23
On 12/23/2010 10:50 AM, Dhinesh wrote:
> That's wrong, but i need to load data to particular pin so that i
> reffered to (1<<21), thats wrong i too know. please provide the
> solution. I could have used IOPIN0 register, but that wont work.
You already know how to raise or lower the Latch and Clock pins. How
come that you can't solve the same problem with the Data pin?
--
Timo
> That's wrong, but i need to load data to particular pin so that i
> reffered to (1<<21), thats wrong i too know. please provide the
> solution. I could have used IOPIN0 register, but that wont work.
You already know how to raise or lower the Latch and Clock pins. How
come that you can't solve the same problem with the Data pin?
--
Timo
Reply by ●December 23, 20102010-12-23
On Thu, 2010-12-23 at 11:06 +0200, Timo wrote:
> You already know how to raise or lower the Latch and Clock pins. How
> come that you can't solve the same problem with the Data pin?
I think he does not know how to convert the bytes
to a bit pattern on the IO pin.
For example : in bu[] he has 4 bytes and in the
for() loop he indexes it as being 8 bytes.
roelof
> You already know how to raise or lower the Latch and Clock pins. How
> come that you can't solve the same problem with the Data pin?
I think he does not know how to convert the bytes
to a bit pattern on the IO pin.
For example : in bu[] he has 4 bytes and in the
for() loop he indexes it as being 8 bytes.
roelof
Reply by ●December 23, 20102010-12-23
I already tried that method of spiting bytes to bits and feeding them to GPIO
that too dosent works. This is the program of it.
#include
#define Data_Pin (1 << 21)
#define Data_DIR_SET (IO0DIR |= Data_Pin)
#define Data_SET (IO0SET = Data_Pin)
#define Data_CLR (IO0CLR = Data_Pin)
#define Clock (1 << 22)
#define Clock_DIR_SET (IO0DIR |= Clock)
#define Clock_SET (IO0SET = Clock)
#define Clock_CLR (IO0CLR = Clock)
#define Latch (1 << 23)
#define Latch_DIR_SET (IO0DIR |= Latch)
#define Latch_SET (IO0SET = Latch)
#define Latch_CLR (IO0CLR = Latch)
#define S_Length(a) (sizeof(a) / sizeof(*(a)))
unsigned byte_idx;
unsigned char data_to_send[] = {0x01,0x00};
unsigned int i;
void delay(int count)
{
int j=0,i=0;
for(j=0;j {
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
void Data_load(unsigned char to_send)
{
Clock_CLR;
Latch_CLR;
for (i = 0; i < 16; i++){
if (to_send & 1) {
Data_SET;
}
else {
Data_CLR;
}
to_send >>= 1;
//delay(1);
Clock_SET ;
delay(1);
Clock_CLR;
delay(1);
}
Latch_SET;
delay(10);
Latch_CLR;
}
int main(void)
{
while(1)
{
for (byte_idx = 0; byte_idx < S_Length(data_to_send); byte_idx++)
{
Data_load(data_to_send[byte_idx]);
}
}
}
Regards
Dhinesh Kumar .R
Embedded Developer (R&D)
Hawk Technologies Pvt Ltd
--- On Thu, 23/12/10, Timo wrote:
From: Timo
Subject: Re: [lpc2000] Loading data serially on a GPIO pin.
To: l...
Date: Thursday, 23 December, 2010, 9:06 AM
On 12/23/2010 10:50 AM, Dhinesh wrote:
> That's wrong, but i need to load data to particular pin so that i
> reffered to (1<<21), thats wrong i too know. please provide the
> solution. I could have used IOPIN0 register, but that wont work.
You already know how to raise or lower the Latch and Clock pins. How
come that you can't solve the same problem with the Data pin?
--
Timo
#include
#define Data_Pin (1 << 21)
#define Data_DIR_SET (IO0DIR |= Data_Pin)
#define Data_SET (IO0SET = Data_Pin)
#define Data_CLR (IO0CLR = Data_Pin)
#define Clock (1 << 22)
#define Clock_DIR_SET (IO0DIR |= Clock)
#define Clock_SET (IO0SET = Clock)
#define Clock_CLR (IO0CLR = Clock)
#define Latch (1 << 23)
#define Latch_DIR_SET (IO0DIR |= Latch)
#define Latch_SET (IO0SET = Latch)
#define Latch_CLR (IO0CLR = Latch)
#define S_Length(a) (sizeof(a) / sizeof(*(a)))
unsigned byte_idx;
unsigned char data_to_send[] = {0x01,0x00};
unsigned int i;
void delay(int count)
{
int j=0,i=0;
for(j=0;j {
/* At 60Mhz, the below loop introduces
delay of 10 us */
for(i=0;i<35;i++);
}
}
void Data_load(unsigned char to_send)
{
Clock_CLR;
Latch_CLR;
for (i = 0; i < 16; i++){
if (to_send & 1) {
Data_SET;
}
else {
Data_CLR;
}
to_send >>= 1;
//delay(1);
Clock_SET ;
delay(1);
Clock_CLR;
delay(1);
}
Latch_SET;
delay(10);
Latch_CLR;
}
int main(void)
{
while(1)
{
for (byte_idx = 0; byte_idx < S_Length(data_to_send); byte_idx++)
{
Data_load(data_to_send[byte_idx]);
}
}
}
Regards
Dhinesh Kumar .R
Embedded Developer (R&D)
Hawk Technologies Pvt Ltd
--- On Thu, 23/12/10, Timo wrote:
From: Timo
Subject: Re: [lpc2000] Loading data serially on a GPIO pin.
To: l...
Date: Thursday, 23 December, 2010, 9:06 AM
On 12/23/2010 10:50 AM, Dhinesh wrote:
> That's wrong, but i need to load data to particular pin so that i
> reffered to (1<<21), thats wrong i too know. please provide the
> solution. I could have used IOPIN0 register, but that wont work.
You already know how to raise or lower the Latch and Clock pins. How
come that you can't solve the same problem with the Data pin?
--
Timo
Reply by ●December 23, 20102010-12-23
Why are you rotating your bytes, passed in to your serialize function, by 16 ? A
byte only has 8 bits!!!!!!!
--- In l..., Dhinesh Kumar wrote:
>
> I already tried that method of spiting bytes to bits and feeding them to GPIO that too dosent works. This is the program of it.
>
> #include
>
> #define Data_Pin (1 << 21)
> #define Data_DIR_SET (IO0DIR |= Data_Pin)
> #define Data_SET (IO0SET = Data_Pin)
> #define Data_CLR (IO0CLR = Data_Pin)
>
> #define Clock (1 << 22)
> #define Clock_DIR_SET (IO0DIR |= Clock)
> #define Clock_SET (IO0SET = Clock)
> #define Clock_CLR (IO0CLR = Clock)
>
> #define Latch (1 << 23)
> #define Latch_DIR_SET (IO0DIR |= Latch)
> #define Latch_SET (IO0SET = Latch)
> #define Latch_CLR (IO0CLR = Latch)
>
> #define S_Length(a) (sizeof(a) / sizeof(*(a)))
>
> unsigned byte_idx;
> unsigned char data_to_send[] = {0x01,0x00};
> unsigned int i;
>
>
> void delay(int count)
> {
> int j=0,i=0;
>
> for(j=0;j > {
> /* At 60Mhz, the below loop introduces
> delay of 10 us */
> for(i=0;i<35;i++);
> }
> }
>
> void Data_load(unsigned char to_send)
> {
> Clock_CLR;
> Latch_CLR;
> for (i = 0; i < 16; i++){
>
> if (to_send & 1) {
>
> Data_SET;
> }
> else {
>
> Data_CLR;
> }
>
> to_send >>= 1;
> //delay(1);
> Clock_SET ;
> delay(1);
> Clock_CLR;
> delay(1);
> }
> Latch_SET;
> delay(10);
> Latch_CLR;
> }
>
> int main(void)
> {
>
> while(1)
> {
>
> for (byte_idx = 0; byte_idx < S_Length(data_to_send); byte_idx++)
> {
>
> Data_load(data_to_send[byte_idx]);
>
> }
>
> }
>
> }
>
>
> Regards
>
> Dhinesh Kumar .R
>
> Embedded Developer (R&D)
>
> Hawk Technologies Pvt Ltd
>
> --- On Thu, 23/12/10, Timo wrote:
>
> From: Timo
> Subject: Re: [lpc2000] Loading data serially on a GPIO pin.
> To: l...
> Date: Thursday, 23 December, 2010, 9:06 AM
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On 12/23/2010 10:50 AM, Dhinesh wrote:
>
> > That's wrong, but i need to load data to particular pin so that i
>
> > reffered to (1<<21), thats wrong i too know. please provide the
>
> > solution. I could have used IOPIN0 register, but that wont work.
>
>
>
> You already know how to raise or lower the Latch and Clock pins. How
>
> come that you can't solve the same problem with the Data pin?
>
>
>
> --
>
>
>
> Timo
>
--- In l..., Dhinesh Kumar wrote:
>
> I already tried that method of spiting bytes to bits and feeding them to GPIO that too dosent works. This is the program of it.
>
> #include
>
> #define Data_Pin (1 << 21)
> #define Data_DIR_SET (IO0DIR |= Data_Pin)
> #define Data_SET (IO0SET = Data_Pin)
> #define Data_CLR (IO0CLR = Data_Pin)
>
> #define Clock (1 << 22)
> #define Clock_DIR_SET (IO0DIR |= Clock)
> #define Clock_SET (IO0SET = Clock)
> #define Clock_CLR (IO0CLR = Clock)
>
> #define Latch (1 << 23)
> #define Latch_DIR_SET (IO0DIR |= Latch)
> #define Latch_SET (IO0SET = Latch)
> #define Latch_CLR (IO0CLR = Latch)
>
> #define S_Length(a) (sizeof(a) / sizeof(*(a)))
>
> unsigned byte_idx;
> unsigned char data_to_send[] = {0x01,0x00};
> unsigned int i;
>
>
> void delay(int count)
> {
> int j=0,i=0;
>
> for(j=0;j > {
> /* At 60Mhz, the below loop introduces
> delay of 10 us */
> for(i=0;i<35;i++);
> }
> }
>
> void Data_load(unsigned char to_send)
> {
> Clock_CLR;
> Latch_CLR;
> for (i = 0; i < 16; i++){
>
> if (to_send & 1) {
>
> Data_SET;
> }
> else {
>
> Data_CLR;
> }
>
> to_send >>= 1;
> //delay(1);
> Clock_SET ;
> delay(1);
> Clock_CLR;
> delay(1);
> }
> Latch_SET;
> delay(10);
> Latch_CLR;
> }
>
> int main(void)
> {
>
> while(1)
> {
>
> for (byte_idx = 0; byte_idx < S_Length(data_to_send); byte_idx++)
> {
>
> Data_load(data_to_send[byte_idx]);
>
> }
>
> }
>
> }
>
>
> Regards
>
> Dhinesh Kumar .R
>
> Embedded Developer (R&D)
>
> Hawk Technologies Pvt Ltd
>
> --- On Thu, 23/12/10, Timo wrote:
>
> From: Timo
> Subject: Re: [lpc2000] Loading data serially on a GPIO pin.
> To: l...
> Date: Thursday, 23 December, 2010, 9:06 AM
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> On 12/23/2010 10:50 AM, Dhinesh wrote:
>
> > That's wrong, but i need to load data to particular pin so that i
>
> > reffered to (1<<21), thats wrong i too know. please provide the
>
> > solution. I could have used IOPIN0 register, but that wont work.
>
>
>
> You already know how to raise or lower the Latch and Clock pins. How
>
> come that you can't solve the same problem with the Data pin?
>
>
>
> --
>
>
>
> Timo
>
Reply by ●December 23, 20102010-12-23
I had done that to my friend but it doesn't works. Program compiles it but
on hardware implementation its not working.
Regards
Dhinesh Kumar .R
Embedded Developer (R&D)
Hawk Technologies Pvt Ltd
--- On Thu, 23/12/10, roelof 't Hooft wrote:
From: roelof 't Hooft
Subject: Re: [lpc2000] Loading data serially on a GPIO pin.
To: l...
Date: Thursday, 23 December, 2010, 9:13 AM
On Thu, 2010-12-23 at 11:06 +0200, Timo wrote:
> You already know how to raise or lower the Latch and Clock pins. How
> come that you can't solve the same problem with the Data pin?
I think he does not know how to convert the bytes
to a bit pattern on the IO pin.
For example : in bu[] he has 4 bytes and in the
for() loop he indexes it as being 8 bytes.
roelof
Regards
Dhinesh Kumar .R
Embedded Developer (R&D)
Hawk Technologies Pvt Ltd
--- On Thu, 23/12/10, roelof 't Hooft wrote:
From: roelof 't Hooft
Subject: Re: [lpc2000] Loading data serially on a GPIO pin.
To: l...
Date: Thursday, 23 December, 2010, 9:13 AM
On Thu, 2010-12-23 at 11:06 +0200, Timo wrote:
> You already know how to raise or lower the Latch and Clock pins. How
> come that you can't solve the same problem with the Data pin?
I think he does not know how to convert the bytes
to a bit pattern on the IO pin.
For example : in bu[] he has 4 bytes and in the
for() loop he indexes it as being 8 bytes.
roelof
Reply by ●December 23, 20102010-12-23
On 12/23/2010 12:08 PM, Dhinesh Kumar wrote:
> I already tried that method of spiting bytes to bits and feeding them to
> GPIO that too dosent works. This is the program of it.
*How* it doesn't work. For example, do you see *any* of the signals
toggling (if not, hint: are you sure you have set them output).
--
Timo
> I already tried that method of spiting bytes to bits and feeding them to
> GPIO that too dosent works. This is the program of it.
*How* it doesn't work. For example, do you see *any* of the signals
toggling (if not, hint: are you sure you have set them output).
--
Timo
Reply by ●December 23, 20102010-12-23
On Thu, 2010-12-23 at 15:38 +0530, Dhinesh Kumar wrote:
> #define S_Length(a) (sizeof(a) / sizeof(*(a)))
You are dividing 2 by 1, the result is 2.
for(byte_idx = 0; byte_idx < sizeof(data_to_send); byte_idx++)
> if (to_send & 1)
I find it more clearly to use hex numbers for a statement
in the line above, like :
if(to_send & 0x01)
roelof
> #define S_Length(a) (sizeof(a) / sizeof(*(a)))
You are dividing 2 by 1, the result is 2.
for(byte_idx = 0; byte_idx < sizeof(data_to_send); byte_idx++)
> if (to_send & 1)
I find it more clearly to use hex numbers for a statement
in the line above, like :
if(to_send & 0x01)
roelof