Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Sending 16Bit serial Data

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Dr.Nokill

Bascom Member



Joined: 18 Jul 2004
Posts: 1

PostPosted: Sun Jul 18, 2004 2:38 pm    Post subject: Sending 16Bit serial Data Reply with quote

Hello,

i need to controll a chip with the help of a microcontroller. I have to send serial data to this chip.
I have to set a pin EN to LOW state and when the CLOCK goes HIGH I have to send the MSB. on every rising edge of the CLOCK i have to send another Bit to the chip while EN stays LOW, after 16bit the EN is set to high.

With the standard SPI $serialoutput datalength is 8Bit.
How can I set it to 16Bit, or how can i send syncron 16 bit serial data to an external device.

(this is my first trie with µC...)


Thank you for your help
Back to top
View user's profile
DJD XTREEM

Bascom Member



Joined: 24 Jun 2004
Posts: 190
Location: 127.0.0.1

netherlands.gif
PostPosted: Mon Sep 13, 2004 8:49 am    Post subject: Reply with quote

I need to send an 14 or 16 bit HEX code to a device::

For example (this code is in HEX): 86 00 00 04 00 01 0C
But also this one:: 87 00 00 05 08 40 09 5D

This all have to be acivated on key presses..

The key systems i'sn't the problem.. But how do i have to send those codes?? Confused

Need a quick solution.. Because i need it tommorow to run Shocked Sad

So please help...

_________________
Bascom AVR 1.11.8.8 full version
STK500 Programmer
ISP Programmer
Back to top
View user's profile Visit poster's website MSN Messenger
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 948
Location: the Netherlands

netherlands.gif
PostPosted: Mon Sep 13, 2004 5:56 pm    Post subject: Reply with quote

@ Dr.Nokill

Make you own SPI, its not so hard.
Put your bit data in two bytes, then assign bit by bit the bit value to a portpin.
Psuedo code:

Set a portpin low 'enable - look at the reset statement

Set a portpin high 'clock - look at the set statement
Set a portpin to the value of the bit index of a byte 'data - portb.2 = var1.0
Set the clockpin low
proberly wait for a while 'look at the waitms statement

Set a portpin high
Set a portpin to the value of the bit index of a byte 'data - portb.2 = var1.1
Set the clockpin low
proberly wait for a while

repeat this 16 times

Set the enablepin high

Frank.

ps: if this don't work you have to control the portpins at the same time, in this case you must combine the clock and the data pin in a byte and control the port with the byte you just have made.
Back to top
View user's profile
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 948
Location: the Netherlands

netherlands.gif
PostPosted: Mon Sep 13, 2004 6:02 pm    Post subject: Reply with quote

@ DJD

You don't send BITS but BYTES, in your case 7 or 8 bytes.
So you can use the normal SPI routines.
Put all your variabele in an array and call SPIOUT with the number of bytes you want to send.

dim A(10) as byte
Spiout A(1) , 8
Spiout A(1) , 7
Back to top
View user's profile
DJD XTREEM

Bascom Member



Joined: 24 Jun 2004
Posts: 190
Location: 127.0.0.1

netherlands.gif
PostPosted: Mon Sep 13, 2004 6:19 pm    Post subject: Reply with quote

Well i did some try's today..

But have some problems with the HEX codes.. Because when i use a spy cable in combination with RSlook232 (rs232 spy software) the code that is set on de serial line isn't the hex code that i gave to send..

And some other try's to send the code on different ways by bascom resulting in compiler errors.. Tripple checked the help files of bascom but can't get those codes on the serial line..

Anyone sugestions??

_________________
Bascom AVR 1.11.8.8 full version
STK500 Programmer
ISP Programmer
Back to top
View user's profile Visit poster's website MSN Messenger
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 948
Location: the Netherlands

netherlands.gif
PostPosted: Mon Sep 13, 2004 6:39 pm    Post subject: Reply with quote

Hi,

When you use the hardeware SPI it is possible to set what bit is send first MSB or LSB.
Maybe the bytes are send in reverse, this is easy to check for you.
If not fill an array with known values like 1, 2, 3, 4, 5 and see what happens if you send these.
Another possibility is that you confuse HEX en DECIMAL.

Frank.
Back to top
View user's profile
DJD XTREEM

Bascom Member



Joined: 24 Jun 2004
Posts: 190
Location: 127.0.0.1

netherlands.gif
PostPosted: Tue Sep 14, 2004 9:32 am    Post subject: Reply with quote

Well i tryed some things again..
But with no luck..
The only thing that it has to do is send some HEX strings over the serial line..

for example when i use this to send a code::

Code:
Config Portd = Output                                       'Uart on port d

Do

Print "FA 00 0A FB 87 00 00 05 08 40 09 5D FF"                          'Hex string to send
Wait 1
Loop

End

Also tryed it without spaces Tryed it as a string and as like this::
Code:
Dim B1 As Byte , B2 As Byte , B3 As Byte , B4 As Byte , B5 As Byte , B6 As Byte , B7 As Byte , B8 As Byte , B9 As Byte , B10 As Byte , B11 As Byte , B12 As Byte , B13 As Byte

B1 = 250
B2 = 0
B3 = 10
B4 = 251
B5 = 135
B6 = 0
B7 = 0
B8 = 5
B9 = 8
B10 = 64
B11 = 9
B12 = 93
B13 = 255


Do
Print Hex(b1) ; Hex(b2) ; Hex(b3) ; Hex(b4) ; Hex(b5) ; Hex(b6) ; Hex(b7) ; Hex(b8) ; Hex(b9) ; Hex(b10) ; Hex(b11) ; Hex(b12) ; Hex(b13)       'print in hexa notation
Wait 1
Loop
End

This will represent the code in HEX.. If only if i read it out on Character.. If i do a serial readout on HEX i only get some numbers like: 30 38 34 30 30 39 35 44 46 46 0D 0A
I don't understand it anymore.. Crying or Very sad

Why is it so difficult to just send a HEX string over serial conection..

_________________
Bascom AVR 1.11.8.8 full version
STK500 Programmer
ISP Programmer
Back to top
View user's profile Visit poster's website MSN Messenger
philm

Bascom Member



Joined: 14 Jul 2004
Posts: 138
Location: Australia

australia.gif
PostPosted: Tue Sep 14, 2004 11:45 am    Post subject: Reply with quote

DJD XTREEM wrote:
i only get some numbers like: 30 38 34 30 30 39 35 44 46 46 0D 0A
I don't understand it anymore.. Crying or Very sad

Why is it so difficult to just send a HEX string over serial conection..

I think you have done exactly what you said "HEX string"
&H30 = "0", &H38 = "8", &H34="4", &H39="9".
I think you are getting mixed up with hex string and hex and just plain integer
An integer with a weight of eg 65 = &H41. If I was to interpret it as ascii, it would = "A"
If you send 65 to via the serial port and your terminal program interpret it as ascii, then you would see the letter "A".
If you send 7 (ascii bel) to via the serial port and your terminal program interpret it as ascii, then you would hear a beep.
Hope it helps
Back to top
View user's profile
Frankeman

Bascom Member



Joined: 11 Aug 2004
Posts: 948
Location: the Netherlands

netherlands.gif
PostPosted: Tue Sep 14, 2004 9:31 pm    Post subject: Reply with quote

Normaly you send values not hex codes.
The little example shows how to do this.
Code:

Dim B(13) As Byte

B(1) = 65  'decimal
B(2) = &h42  'hexadecimal
B(3) = &B01000011  'binair
B(4) = 68
B(5) = &H45
B(6) = &B01000110
B(7) = 71
B(8) = &H48
B(9) = &B01001001
B(10) = 74
B(11) = &H4B
B(12) = &B01001100
B(13) = 77

Printbin B(1), 13

End
 
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 6198
Location: Holland

blank.gif
PostPosted: Tue Sep 14, 2004 9:54 pm    Post subject: Reply with quote

Yes, that explains it well. But to make sure here is some more info.
When we have a variable named B, and it is of the type BYTE, it can hold values from 0-255.
Ok, let say we assign it value of 16 (dec). This is :
16 (dec)
10 (hex)
0001 0000 (bin)
this is just different notation. the value remains the same.

Now when we send this value to the TX pin, we can sent it in different ways.
When we like to send the binary value, we need to sent just 1 byte : PRINT chr(b);
The ; we use so no CR+LF is added.

When we like to send it as a number (dec) we use : PRINT B ;
This will convert the value B into "16" and will thus send a byte with value 49 and 54. (ascii value of "1" = 49)

Now when we want to send as HEX, we use : PRINT HEX(b) ;
This will convert the byte into "10" and will send 2 bytes again.

So there is a huge differenc e between sending BINARY data (with CHR or PRINTBIN) and sending the ASCII representation of the value.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum