Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

18F258-I/SP - Simple Question?

Status
Not open for further replies.

gadget00

New Member
I'm just starting out with microcontrollers - I have (I hope) a relatively simple task.

I have a 18F258-I/SP with this PIC Board:
https://microcontrollershop.com/product_info.php?products_id=1436

I also have a SonMicro SM3005 RFID reader which can send tag data over RS232, as it is received.

I am hoping to set up the microcontroller to log this data, so that a computer can retrieve the RFID tag's data later.

I would imagine this code would be simple, but I haven't been able to find any similar project online.

Any help would be appreciated greatly!

Thanks,
Ethan
 
gadget00 said:
I'm just starting out with microcontrollers - I have (I hope) a relatively simple task.

I have a 18F258-I/SP with this PIC Board:
https://microcontrollershop.com/product_info.php?products_id=1436

I also have a SonMicro SM3005 RFID reader which can send tag data over RS232, as it is received.

I am hoping to set up the microcontroller to log this data, so that a computer can retrieve the RFID tag's data later.

I would imagine this code would be simple, but I haven't been able to find any similar project online.
That's more than a newbie project. If you're just starting out, you'll have to learn the basics first. Blink some LEDs. Learn to program, and the various tricks of interfacing different hardware.

RS232 is pretty easy after you get a handle on the basics. It is well covered in the datasheet.
 
futz said:
That's more than a newbie project. If you're just starting out, you'll have to learn the basics first. Blink some LEDs. Learn to program, and the various tricks of interfacing different hardware.

RS232 is pretty easy after you get a handle on the basics. It is well covered in the datasheet.

Thanks for the quick response!

I've done the "Getting Started" tutorials, and understand the basics covered there. But that doesn't seem to mention anything about RS232 input or storing data in the memory.

Do you know of a tutorial that does?

Thanks,
Ethan
 
I've done the "Getting Started" tutorials
There are "Getting Started" tutorials? :p

gadget00 said:
Do you know of a tutorial that does?
Both are pretty well covered in the datasheet. If you don't have it, get it. You NEED it to get anything done with your MCU.

Just looked. You must mean the 18F2580. There is no 258. Datasheet is here.
 
Last edited:
gadget00 said:
I also have a SonMicro SM3005 RFID reader which can send tag data over RS232, as it is received.

I am hoping to set up the microcontroller to log this data, so that a computer can retrieve the RFID tag's data later.
How much data do you expect the RFID reader to generate? That PIC doesn't have much storage space. If it's not too much data you could write to unused program memory or the 256 bytes of EEPROM, but that isn't very roomy. And if you're not careful your data will "overflow" and clobber your program.

You could use a 25LC1024 SPI Serial Flash chip or similar. Very easy to use and about 128K of non-volatile storage.

Or you could do a SD card interface and have several gigabytes of storage. It's a fair bit more difficult to set up and write code for though (I'm just writing the software for mine now). Write the software right and you just pull the card out and plug it into your PC's card reader to transfer the data.
 
Yeah, I was just realizing that. 256 bytes won't get me very far.

Also, I'm going through the data sheet, but as a tutorial, it's not very good. I'd probably need to pair that with some kind of guide that covers what I need to do.

Do you know of a guide for the 25LC1024 that may help me with this project?

I would use the SD card interface, but I'm worried about time and difficulty. I just assumed that writing from TX/RX pins / standard RS232 input into memory would be a simple process, so I'd be able to go to the web and grab some code. I was mistaken!

What do you think my best bet is?



futz said:
How much data do you expect the RFID reader to generate? That PIC doesn't have much storage space. If it's not too much data you could write to unused program memory or the 256 bytes of EEPROM, but that isn't very roomy. And if you're not careful your data will "overflow" and clobber your program.

You could use a 25LC1024 SPI Serial Flash chip or similar. Very easy to use and about 128K of non-volatile storage.

Or you could do a SD card interface and have several gigabytes of storage. It's a fair bit more difficult to set up and write code for though (I'm just writing the software for mine now). Write the software right and you just pull the card out and plug it into your PC's card reader to transfer the data.
 
gadget00 said:
Yeah, I was just realizing that. 256 bytes won't get me very far.
Well, you could probably grab 16K or more of program memory, but that depends on program size. And it still isn't very much space for a datalogger.

Do you know of a guide for the 25LC1024 that may help me with this project?
No. I figured it out with just the datasheet. SPI is dead simple. The 25LC1024 is really easy to work with too.

I would use the SD card interface, but I'm worried about time and difficulty. I just assumed that writing from TX/RX pins / standard RS232 input into memory would be a simple process, so I'd be able to go to the web and grab some code. I was mistaken!
Well, it is a relatively simple process. You won't learn a thing by mooching someone else's code though. That often makes it more difficult. For example, read about Engkhlaif's troubles. He grabbed code off the web and didn't understand it. Even after me and Pommie gave him working code and explained what he needed to do he still couldn't get it going. As far as I know he still doesn't have anything working.

What do you think my best bet is?
If this is for school, do your own work. You'll understand the code 100% better if you've written it yourself. Don't put it off till the last week. Start early and finish early. Relax after the work is done. :D

Once you have things wired up and some code written, then ask specific questions and people here will try to help you. But nobody here will do your homework for you. That kind of crap gets asked here all the time. :p

Draw a schematic. If you ask those specific questions the first thing people will ask is, "Where's your schematic? Let's see your code!".
 
Last edited:
Can someone check out this code and see if I'm doing something wrong or missing something?

The program, obviously, is just supposed to read an input byte and bounce it back. How would I test this, if it's connected up to the PIC Board, above (in the first post)?

Thanks!

#include <p18f258.h>
#include <sw_uart.h>
#include <delays.h>
#define config WDT = OFF
#define BAUD 19200
#define CLK 48000000


//Delay Functions
//===============
void DelayTXBitUART(void)
{
char delay_time = (((((2*CLK)/(4*BAUD))+1)/2)-12)/10;
Delay10TCYx (delay_time);
return;
}
void DelayRXHalfBitUART(void)
{
char delay_time = (((((2*CLK)/(8*BAUD))+1)/2)-9)/10;
Delay10TCYx (delay_time);
return;
}
void DelayRXBitUART(void)
{
char delay_time = (((((2*CLK)/(4*BAUD))+1)/2)-14)/10;
Delay10TCYx (delay_time);
return;
}
/////////////////////////////////////////////////////////////

void main( void )
{
char data;
// configure software UART
OpenUART();
while( 1 )
{
data = ReadUART(); //read a byte
WriteUART( data ); //bounce it back
}
}
 
I haven't used the software serial routines and so can't help. Have you tried using the hardware USART (section 18). It will be much simpler to use. If unsure check out this document (Edit, not so good an idea as it's asm). Also, the max clock speed for that chip is 40MHz - you have 48 in your code.

Edit, I think it's as simple as,
Code:
void Setup(){
    TXSTAbits.BRGH=1;
    SPBRG=129;        //from table Pg 188
    TXSTAbits.SYNC=0;
    RCSTAbits.SPEN=1;
    RCSTAbits.CREN=1;
    TXSTAbits.TXEN=1;
}

unsigned char Receive(){
    while(PIR1bits.RCIF==0);
    return RCREG;
}

void Transmit(unsigned char data){
    while(PIR1bits.TXIF==0);
    TXREG=data;
}

However, I can't test it right now.

Mike
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top