SPI.Transfer a string

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
garryp4
Posts: 126
Joined: Mon May 21, 2007 7:18 am
Location: Loveland, CO USA

SPI.Transfer a string

Post by garryp4 » Sat Dec 26, 2020 3:49 pm

I would like to transfer a byte as a string from an eeprom memory. I can transfer a byte in and out with no problem, but can not figure out how to read the byte as a string or convert it to a string.

Thanks!

garryp4
Posts: 126
Joined: Mon May 21, 2007 7:18 am
Location: Loveland, CO USA

Re: SPI.Transfer a string

Post by garryp4 » Sat Dec 26, 2020 9:20 pm

Figured it out. I was not declaring the the string variable with an extra byte for the null character.

Code: Select all

Public Function READ_STRING(p_addr As LongWord) As String * 4

  OPEN_SPI()
  
  Low(mem_cs)
  SPI.Transfer(read_data)             ' Read instruction
  SPI.Transfer(p_addr.byte2)          ' Address byte 2
  SPI.Transfer(p_addr.byte1)          ' Address byte 1
  SPI.Transfer(p_addr.byte0)          ' Address byte 0
  result(3) = SPI.Transfer()
  result(2) = SPI.Transfer()
  result(1) = SPI.Transfer()
  result(0) = SPI.Transfer()
  High(mem_cs)

  SPI.Close
  
End Function
and

Code: Select all

Private Dim
 my_id            As String(5)
I originally had my_id As String(4).

Post Reply